LifeWeb.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /**
  25. * 获取达人信息
  26. * @param string $name
  27. * @return array
  28. */
  29. public function getStarData(string $name = ""): array
  30. {
  31. $param = [
  32. "request_source" => 2,
  33. "keyword" => $name,
  34. "page" => 1,
  35. "page_size" => 10
  36. ];
  37. $resp = Http::asJson()->withHeaders($this->header)->post($this->getaway."/life/alliance/v1/merchant/talent_square/talent/search/?root_life_account_id=7595228109947947043&life_biz_view_id=22&life_account_biz_ids=",$param)->array();
  38. if ($resp['status_code'] <> 0) return [0,'登录过期,请联系管理员'];
  39. if (!isset($resp['talent_list'][0])) return [0,'未获取到达人信息,请确认是否已开通达人权限'];
  40. return [1,$resp['talent_list'][0]];
  41. }
  42. /**
  43. * 获取订单信息
  44. * @param string $orderId
  45. * @return array
  46. */
  47. public function getOrderData(string $orderId = ""): array
  48. {
  49. $param = [
  50. "order_id" => $orderId,
  51. "current_time_ms" => round(microtime(true) * 1000),
  52. "show_reason" => "catering_comprehensive_coupon",
  53. "search_type" => 1,
  54. "source" => 1,
  55. "dito_biz_common_param" => [
  56. "page_id" => "502",
  57. "scene_version" => "management",
  58. "source" => "dlk_pc"
  59. ],
  60. "industry" => "industry_common"
  61. ];
  62. $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();
  63. if (!isset($resp['data']['dito_data']['meta_data'])) return [0,'获取失败'];
  64. $metaData = $resp['data']['dito_data']['meta_data'];
  65. $dataRe = json_decode(json_decode($metaData, true), true);
  66. $orderFee = $dataRe['order_fee']['bill_commissions'];
  67. $starFee = $lifeFee = 0;
  68. foreach ($orderFee as $value) {
  69. if ($value['title'] == "软件服务费") {
  70. $lifeFee = substr($value['amount'],1);
  71. }
  72. if ($value['title'] == "达人服务费") {
  73. $starFee = substr($value['amount'],1);
  74. }
  75. }
  76. return [1,[
  77. "douyin_uid" => $dataRe['order_source']['sale_user_unique_id']??'',
  78. "star_fee" => $starFee,
  79. "life_fee" => $lifeFee,
  80. ]];
  81. }
  82. public function getExpressData(string $expressNo = "",string $mobile = ""): array
  83. {
  84. $url = "https://kzexpress.market.alicloudapi.com/api-mall/api/express/query";
  85. $param = [
  86. "expressNo" => $expressNo,
  87. "mobile" => substr($mobile,-4)
  88. ];
  89. $resp = Http::withHeaders([
  90. "Authorization" => "APPCODE ".sConf("wechat.kd_code")
  91. ])->post($url,$param)->array();
  92. if ($resp['code'] <> 200) {
  93. return [0,''];
  94. }
  95. return [1,$resp['data']];
  96. }
  97. protected function getCookies()
  98. {
  99. return (new SystemConfig)->where(['type' => "life","name" => "cookies"])->value("value");
  100. }
  101. }