HeiMaUtil.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Utils;
  3. use App\Exceptions\CommonException;
  4. use App\Http\Enum\ErrorEnum;
  5. use App\Models\TaobaoPidModel;
  6. use Tool\ShanTaoTool\HttpCurl;
  7. /**
  8. * 黑马淘客工具类
  9. * Class HeiMaUtil
  10. * @package App\Http\Utils
  11. */
  12. class HeiMaUtil extends BaseUtil
  13. {
  14. //基础链接
  15. static $baseUrl = "https://www.heimataoke.com/";
  16. /**
  17. * 根据商品ID获取商品的佣金信息
  18. * @param $goodsId
  19. */
  20. public static function gaoYongZhuanLian($goodsId,$pid)
  21. {
  22. //根据pid找到黑马授权的账号密钥
  23. $taobao = TaobaoPidModel::query()
  24. ->where("adzone_id",$pid)
  25. ->first();
  26. $url = self::$baseUrl."api-zhuanlian";
  27. $params = [
  28. "appkey"=>$taobao["heima_app_key"],
  29. "appsecret"=>$taobao["heima_app_secret"],
  30. "sid"=>$taobao["heima_sid"],
  31. "pid"=>$taobao["adzone_code"],
  32. "num_iid"=>$goodsId,
  33. "signurl"=>1
  34. ];
  35. $res = HttpCurl::getCurl($url,$params);
  36. $url = $res["url"];
  37. $response = HttpCurl::getCurl($url);
  38. if(isset($response["tbk_privilege_get_response"])){
  39. return $response["tbk_privilege_get_response"]["result"]["data"];
  40. }
  41. $instance = new LoggerFactoryUtil(HeiMaUtil::class);
  42. $instance->info("上游返回信息:".json_encode($response));
  43. throw new CommonException(ErrorEnum::ERROR_SYSTEM);
  44. }
  45. /**
  46. * 获取订单列表
  47. */
  48. public static function getOrderList($heima)
  49. {
  50. $url = self::$baseUrl."api-order";
  51. $params = [
  52. "appkey"=>$heima["heima_app_key"],
  53. "appsecret"=>$heima["heima_app_secret"],
  54. "sid"=>$heima["heima_sid"],
  55. "start_time"=>date("Y-m-d H:i:s",time()-20*60),
  56. "end_time"=>date("Y-m-d H:i:s"),
  57. // "start_time"=>"2021-12-17 13:40:00",
  58. // "end_time"=>"2021-12-17 15:40:00",
  59. "page_no"=>1,
  60. "page_size"=>100,
  61. "signurl"=>1,
  62. "query_type"=>4
  63. ];
  64. $res = HttpCurl::getCurl($url,$params);
  65. if(isset($res["error"])){
  66. //存在错误则报警
  67. BaseUtil::sendBaoJing("获取订单失败",$res,"定时获取黑马淘客订单");
  68. }
  69. $url = $res["url"];
  70. $response = HttpCurl::getCurl($url);
  71. if(!isset($response["tbk_sc_order_details_get_response"])){
  72. //存在错误则报警
  73. BaseUtil::sendBaoJing("获取订单失败",$response,"定时获取黑马淘客订单");
  74. }
  75. return $response["tbk_sc_order_details_get_response"]["data"]["results"];
  76. }
  77. }