LifeWeb.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. protected function getCookies()
  83. {
  84. return (new SystemConfig)->where(['type' => "life","name" => "cookies"])->value("value");
  85. }
  86. }