|
@@ -0,0 +1,241 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace App\Http\Utils\JingDong;
|
|
|
+
|
|
|
+
|
|
|
+use App\Exceptions\CommonException;
|
|
|
+use App\Http\Utils\BaseUtil;
|
|
|
+use App\Http\Utils\LoggerFactoryUtil;
|
|
|
+use Tool\ShanTaoTool\HttpCurl;
|
|
|
+
|
|
|
+class JingDongUtil extends BaseUtil
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 生成sign
|
|
|
+ * @param $params array 参数
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public static function generateSign($params)
|
|
|
+ {
|
|
|
+ $secret = config("utilJingDong")["appSecret"];
|
|
|
+ ksort($params);
|
|
|
+ $str = $secret; // $secret为分配的密钥
|
|
|
+ foreach ($params as $key => $value) {
|
|
|
+ $str .= $key . $value;
|
|
|
+ }
|
|
|
+ $str .= $secret;
|
|
|
+ $sign = md5($str);
|
|
|
+ $sign = strtoupper($sign);
|
|
|
+ return $sign;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $req 请求参数
|
|
|
+ * @param $method 请求接口
|
|
|
+ * @param $token
|
|
|
+ * @return mixed
|
|
|
+ * @throws CommonException
|
|
|
+ */
|
|
|
+ public static function jDRequestApi($req, $method, $token='')
|
|
|
+ {
|
|
|
+ $appKey = config("utilJingDong")["appKey"];
|
|
|
+ $domain = config("utilJingDong")["domain"];
|
|
|
+ $params = [
|
|
|
+ "method" => $method,
|
|
|
+ "app_key" => $appKey,
|
|
|
+ "timestamp" => date("Y-m-d H:i:s"),
|
|
|
+ "format" => "json",
|
|
|
+ "v" => "1.0",
|
|
|
+ "sign_method" => "md5",
|
|
|
+ "360buy_param_json" => count($req)==0?"{}":json_encode($req)
|
|
|
+ ];
|
|
|
+ if($token){
|
|
|
+ $params["access_token"] = $token;
|
|
|
+ }
|
|
|
+
|
|
|
+ $params["sign"] = self::generateSign($params);
|
|
|
+ $domain = $domain . "?" . http_build_query($params);
|
|
|
+ $res = HttpCurl::postCurl($domain);
|
|
|
+ $arr = explode(".",$method);
|
|
|
+ $nextKey = $arr[count($arr)-1]."Result";
|
|
|
+
|
|
|
+ $responseKey = str_replace(".","_",$method)."_responce";
|
|
|
+
|
|
|
+ $log = new LoggerFactoryUtil(JingDongUtil::class);
|
|
|
+ $log->info(json_encode(["params" => $params, "res" => $res]));
|
|
|
+ if(!isset($res[$responseKey])){
|
|
|
+ throw new CommonException(ErrorEnum::EXCEPTION_ERROR);
|
|
|
+ }
|
|
|
+ $res = $res[$responseKey][$nextKey];
|
|
|
+ $res = json_decode($res,true);
|
|
|
+
|
|
|
+ if ($res["code"] == 200) {
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ dd($res);
|
|
|
+ throw new CommonException([500,$res["message"]]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分类
|
|
|
+ */
|
|
|
+ public static function getCategory()
|
|
|
+ {
|
|
|
+// $params = [
|
|
|
+// "req"=>[
|
|
|
+// "parentId"=>0,
|
|
|
+// "grade"=>0
|
|
|
+// ]
|
|
|
+// ];
|
|
|
+//
|
|
|
+// return self::jDRequestApi($params,"jd.union.open.category.goods.get");
|
|
|
+ return [
|
|
|
+ [
|
|
|
+ "id"=>1,
|
|
|
+ "name"=>"好券商品"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>2,
|
|
|
+ "name"=>"精选卖场"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>10,
|
|
|
+ "name"=>"9.9包邮"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>15,
|
|
|
+ "name"=>"京东配送"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>32,
|
|
|
+ "name"=>"京东好物"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>22,
|
|
|
+ "name"=>"实时热销榜"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>33,
|
|
|
+ "name"=>"京东秒杀"
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "id"=>34,
|
|
|
+ "name"=>"拼购商品"
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据商品分类获取商品列表
|
|
|
+ * @param $cateId
|
|
|
+ */
|
|
|
+ public static function getGoodsListByCategory($cateId,$page)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "goodsReqDTO"=>[
|
|
|
+ "cid1"=>$cateId,
|
|
|
+ "pageIndex"=>$page
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return self::jDRequestApi($params,"jd.union.open.goods.query");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取商品详情页
|
|
|
+ * @param $goodsId
|
|
|
+ */
|
|
|
+ public static function getGoodsDetail($goodsId)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "goodsReqDTO"=>[
|
|
|
+ "skuIds"=>[$goodsId]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return self::jDRequestApi($params,"jd.union.open.goods.query");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建联盟推广位
|
|
|
+ */
|
|
|
+ public static function createdPid()
|
|
|
+ {
|
|
|
+ //目前默认创建平台的后续会根据用户的进行修改
|
|
|
+ $oauth = UserOauthModel::query()
|
|
|
+ ->where("api_user_id",0)
|
|
|
+ ->where("platform_type",PlatformTypeEnum::JINGDOND)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ "positionReq"=>[
|
|
|
+ "unionId"=>$oauth["lianmeng_id"],
|
|
|
+ "key"=>$oauth["lianmeng_key"],
|
|
|
+ "unionType"=>3,
|
|
|
+ "type"=>4,
|
|
|
+ "spaceNameList"=>["pid"]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return self::jDRequestApi($params,"jd.union.open.position.create");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据商品ID进行转链
|
|
|
+ * @param $goodsId
|
|
|
+ */
|
|
|
+ public static function transferGoods($goodsId,$pid)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "goodsReqDTO"=>[
|
|
|
+ "skuIds"=>[$goodsId]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $data = self::jDRequestApi($params,"jd.union.open.goods.query")["data"][0];
|
|
|
+
|
|
|
+ //目前默认创建平台的后续会根据用户的进行修改
|
|
|
+ $oauth = UserOauthModel::query()
|
|
|
+ ->where("api_user_id",0)
|
|
|
+ ->where("platform_type",PlatformTypeEnum::JINGDOND)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+
|
|
|
+ $arr = [
|
|
|
+ "promotionCodeReq"=>[
|
|
|
+ "materialId"=>$data["materialUrl"],
|
|
|
+// "subUnionId"=>"ceshi",
|
|
|
+ "positionId"=>$pid,
|
|
|
+ "unionId"=>$oauth["lianmeng_id"],
|
|
|
+ "chainType"=>3
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return self::jDRequestApi($arr,"jd.union.open.promotion.byunionid.get");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取京东联盟订单列表
|
|
|
+ * @return mixed
|
|
|
+ * @throws CommonException
|
|
|
+ */
|
|
|
+ public static function getOrderList()
|
|
|
+ {
|
|
|
+ //目前默认创建平台的后续会根据用户的进行修改
|
|
|
+ $oauth = UserOauthModel::query()
|
|
|
+ ->where("api_user_id",0)
|
|
|
+ ->where("platform_type",PlatformTypeEnum::JINGDOND)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ "orderReq"=>[
|
|
|
+ "pageIndex"=>1,
|
|
|
+ "pageSize"=>20,
|
|
|
+ "type"=>1,
|
|
|
+ "startTime"=>"2021-12-22 14:00:00",
|
|
|
+ "endTime"=>"2021-12-22 14:30:00",
|
|
|
+ "childUnionId"=>1001268394,
|
|
|
+// "childUnionId"=>$oauth["lianmeng_id"],
|
|
|
+// "key"=>"ece3b6ab1c8b87a7fa80247b92da4441abcd2d8e862e22e4d374ef1cfbd4fb0373cf264e3f54b391",
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return self::jDRequestApi($params,"jd.union.open.order.row.query");
|
|
|
+ }
|
|
|
+}
|