123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Http\Utils;
- use App\Exceptions\CommonException;
- use App\Http\Enum\ErrorEnum;
- use App\Models\TaobaoPidModel;
- use Tool\ShanTaoTool\HttpCurl;
- /**
- * 黑马淘客工具类
- * Class HeiMaUtil
- * @package App\Http\Utils
- */
- class HeiMaUtil extends BaseUtil
- {
- //基础链接
- static $baseUrl = "https://www.heimataoke.com/";
- /**
- * 根据商品ID获取商品的佣金信息
- * @param $goodsId
- */
- public static function gaoYongZhuanLian($goodsId,$pid)
- {
- //根据pid找到黑马授权的账号密钥
- $taobao = TaobaoPidModel::query()
- ->where("adzone_id",$pid)
- ->first();
- $url = self::$baseUrl."api-zhuanlian";
- $params = [
- "appkey"=>$taobao["heima_app_key"],
- "appsecret"=>$taobao["heima_app_secret"],
- "sid"=>$taobao["heima_sid"],
- "pid"=>$taobao["adzone_code"],
- "num_iid"=>$goodsId,
- "signurl"=>1
- ];
- $res = HttpCurl::getCurl($url,$params);
- $url = $res["url"];
- $response = HttpCurl::getCurl($url);
- if(isset($response["tbk_privilege_get_response"])){
- return $response["tbk_privilege_get_response"]["result"]["data"];
- }
- $instance = new LoggerFactoryUtil(HeiMaUtil::class);
- $instance->info("上游返回信息:".json_encode($response));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- /**
- * 获取订单列表
- */
- public static function getOrderList($heima)
- {
- $url = self::$baseUrl."api-order";
- $params = [
- "appkey"=>$heima["heima_app_key"],
- "appsecret"=>$heima["heima_app_secret"],
- "sid"=>$heima["heima_sid"],
- "start_time"=>date("Y-m-d H:i:s",time()-20*60),
- "end_time"=>date("Y-m-d H:i:s"),
- // "start_time"=>"2021-12-17 13:40:00",
- // "end_time"=>"2021-12-17 15:40:00",
- "page_no"=>1,
- "page_size"=>100,
- "signurl"=>1,
- "query_type"=>4
- ];
- $res = HttpCurl::getCurl($url,$params);
- if(isset($res["error"])){
- //存在错误则报警
- BaseUtil::sendBaoJing("获取订单失败",$res,"定时获取黑马淘客订单");
- }
- $url = $res["url"];
- $response = HttpCurl::getCurl($url);
- if(!isset($response["tbk_sc_order_details_get_response"])){
- //存在错误则报警
- BaseUtil::sendBaoJing("获取订单失败",$response,"定时获取黑马淘客订单");
- }
- return $response["tbk_sc_order_details_get_response"]["data"]["results"];
- }
- }
|