123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace App\Http\Utils\WeiPinHui;
- use App\Http\Utils\BaseUtil;
- class WeiPinHuiUtil extends BaseUtil
- {
- /**
- * 生成sign
- * @param $params array 参数
- * @return string
- */
- public static function generateSign($params, $req)
- {
- $secret = config("utilWeiPinHui")["appSecret"];
- ksort($params);
- $str = "";
- foreach ($params as $key => $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);
- }
- }
|