$value) { $str .= $key . $value; } $str .= json_encode($req); $sign = hash_hmac('md5', $str, $secret); $sign = strtoupper($sign); return $sign; } /** * @param $req 请求参数 * @param $serviceName 服务名称 * @param $method 请求方法 * @param string $accessToken * @return mixed * @throws CommonException */ public static function weiPinHuiRequestApi($req = [], $serviceName, $method, $accessToken = "") { $appKey = config("utilWeiPinHui")["appKey"]; $domain = config("utilWeiPinHui")["domain"]; $params = [ "service" => $serviceName, "method" => $method, "version" => "1.0.0", "timestamp" => time(), "format" => "json", "appKey" => $appKey, "accessToken" => $accessToken ]; $params["sign"] = self::generateSign($params, $req); $domain = $domain . "?" . http_build_query($params); $res = HttpCurl::postCurl($domain, $req); $log = new LoggerFactoryUtil(WeiPinHuiUtil::class); $log->info(json_encode(["params" => $params, "res" => $res])); if ($res && $res["returnCode"] == 0) { return $res["result"]; } throw new CommonException(ErrorEnum::EXCEPTION_ERROR); } /** * 将商品链接转化为联盟链接 * @param $goodLink 商品链接 * @param $accessToken 授权密钥 */ public static function tranferVipLink($goodLink,$pid,$accessToken) { $params = [ "urlList"=>[$goodLink], "requestId"=>time()."", "chanTag"=>$pid ]; return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionUrlService","genByVIPUrlWithOauth",$accessToken); } /** * 将商品ID转化为联盟链接 * @param $goodsId 商品ID * @param $accessToken 授权密钥 * @return mixed * @throws CommonException */ public static function transferGoodsId($goodsId,$pid, $accessToken) { $params = [ "goodsIdList"=>[$goodsId], "requestId"=>time()."", "chanTag"=>$pid ]; return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionUrlService","genByGoodsIdWithOauth",$accessToken); } /** * 获取联盟商品列表 * @param $params * @param $acessToken * @return mixed * @throws CommonException */ public static function getGoodsList($params, $accessToken) { return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionGoodsService","goodsListWithOauth",$accessToken); } /** * 获取联盟商品详情 * @param $params * @param $acessToken * @return mixed * @throws CommonException */ public static function getGoodsDetail($params, $accessToken) { return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionGoodsService","getByGoodsIdsWithOauth",$accessToken); } /** * 通过搜索获取联盟商品列表 * @param $params * @param $acessToken * @return mixed * @throws CommonException */ public static function getGoodsListBySearch($params, $accessToken) { return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionGoodsService","queryWithOauth",$accessToken); } /** * 获取一级类目 * @return mixed * @throws CommonException */ public static function getCategory($accessToken) { $params = [ "request"=>[ "parentId"=>0, "grade"=>1, "requestId"=>time()."" ] ]; return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionGoodsService","getCategorys",$accessToken); } /** * 获取订单列表 * @param $params * @param $accessToken */ public static function getOrderList($params, $accessToken) { return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionOrderService","orderListWithOauth",$accessToken); } /** * 获取维权订单列表 * @param $params * @param $accessToken */ public static function getRefundOrderList($params, $accessToken) { return self::weiPinHuiRequestApi($params,"com.vip.adp.api.open.service.UnionOrderService","refundOrderListWithOauth",$accessToken); } }