LifeWeb.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\extra\tools;
  3. use app\model\system\SystemConfig;
  4. use yzh52521\EasyHttp\Http;
  5. class LifeWeb
  6. {
  7. protected string $getaway = "https://life.douyin.com";
  8. /**
  9. * 默认header
  10. * @var string[]
  11. */
  12. protected array $header = [];
  13. /**
  14. * 释放授权
  15. * @return $this
  16. */
  17. public function token(): static
  18. {
  19. $this->header = [
  20. "cookie" => $this->getCookies()
  21. ];
  22. return $this;
  23. }
  24. public function getOrderData(string $orderId = ""): array
  25. {
  26. $param = [
  27. "order_id" => $orderId,
  28. "current_time_ms" => round(microtime(true) * 1000),
  29. "show_reason" => "catering_comprehensive_coupon",
  30. "search_type" => 1,
  31. "source" => 1,
  32. "dito_biz_common_param" => [
  33. "page_id" => "502",
  34. "scene_version" => "management",
  35. "source" => "dlk_pc"
  36. ],
  37. "industry" => "industry_common"
  38. ];
  39. $resp = Http::asJson()->withHeaders($this->header)->post($this->getaway."/life/trade_view/v1/management/coupon/sale/get_detail?industry=industry_common&root_life_account_id=7595228109947947043&life_biz_view_id=22&life_account_biz_ids=",$param)->array();
  40. if (!isset($resp['data']['dito_data']['meta_data'])) return [0,'获取失败'];
  41. $metaData = $resp['data']['dito_data']['meta_data'];
  42. $dataRe = json_decode(json_decode($metaData, true), true);
  43. $orderFee = $dataRe['order_fee']['bill_commissions'];
  44. $starFee = $lifeFee = 0;
  45. foreach ($orderFee as $value) {
  46. if ($value['title'] == "软件服务费") {
  47. $lifeFee = substr($value['amount'],1);
  48. }
  49. if ($value['title'] == "达人服务费") {
  50. $starFee = substr($value['amount'],1);
  51. }
  52. }
  53. return [1,[
  54. "douyin_uid" => $dataRe['order_source']['sale_user_unique_id']??'',
  55. "star_fee" => $starFee,
  56. "life_fee" => $lifeFee,
  57. ]];
  58. }
  59. protected function getCookies()
  60. {
  61. return (new SystemConfig)->where(['type' => "life","name" => "cookies"])->value("value");
  62. }
  63. }