MeituanLianmengUtil.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace App\Http\Utils\Meituan;
  3. use App\Exceptions\CommonException;
  4. use App\Http\Bean\Util\Meituan\CouponListParamBean;
  5. use App\Http\Bean\Util\Meituan\OrderListParamBean;
  6. use App\Http\Enum\ErrorEnum;
  7. use App\Http\Enum\MeiTuanLinkTypeEnum;
  8. use App\Http\Utils\BaseUtil;
  9. use Tool\ShanTaoTool\HttpCurl;
  10. class MeituanLianmengUtil extends BaseUtil
  11. {
  12. /**
  13. * 生成sign
  14. * @param $params array 参数
  15. * @return string
  16. */
  17. public static function generateSign($params)
  18. {
  19. $secret = env("MEITUAN_LIANMENG_SECRET");
  20. unset($params["sign"]);
  21. ksort($params);
  22. $str = $secret; // $secret为分配的密钥
  23. foreach($params as $key => $value) {
  24. $str .= $key . $value;
  25. }
  26. $str .= $secret;
  27. $sign = md5($str);
  28. return $sign;
  29. }
  30. /**
  31. * @param $actId int 活动id,可以在联盟活动列表中查看获取
  32. * @param $sid string 推广位ID
  33. * @param $linkType int 链接类型(1、h5链接2、deeplink(唤起)链接3、中间页唤起链接4、微信小程序唤起路径)
  34. * @param $appkey string appkey
  35. */
  36. public static function generateLink($actId,$sid,$linkType,$appkey)
  37. {
  38. $url = "https://runion.meituan.com/generateLink";
  39. $params = [
  40. "actId"=>$actId,
  41. "key"=>$appkey,
  42. "sid"=>$sid,
  43. "linkType"=>$linkType,
  44. "sign"=>""
  45. ];
  46. $sign = self::generateSign($params);
  47. $params["sign"] = $sign;
  48. $res = HttpCurl::getCurl($url,$params);
  49. if($res["status"]!=0){
  50. throw new CommonException(ErrorEnum::ERROR_MEITUAN_LINK);
  51. }
  52. return $res["data"];
  53. }
  54. /**
  55. * 领券结果查询接口
  56. * @param CouponListParamBean $couponListParamBean
  57. */
  58. public static function couponList(CouponListParamBean $couponListParamBean)
  59. {
  60. $url = "https://runion.meituan.com/api/couponList";
  61. $params = [
  62. "key"=>$couponListParamBean->getAppkey(),
  63. "ts"=>time(),
  64. "type"=>$couponListParamBean->getType(),
  65. "sign"=>"",
  66. "startTime"=>$couponListParamBean->getStartTime(),
  67. "endTime"=>$couponListParamBean->getEndTime(),
  68. "page"=>$couponListParamBean->getPage(),
  69. "limit"=>$couponListParamBean->getLimit(),
  70. "sid"=>$couponListParamBean->getSid()
  71. ];
  72. $sign = self::generateSign($params);
  73. $params["sign"] = $sign;
  74. $res = HttpCurl::getCurl($url,$params);
  75. return $res;
  76. }
  77. /**
  78. * 获取订单列表接口
  79. * @param OrderListParamBean $orderListParamBean
  80. */
  81. public static function orderList(OrderListParamBean $orderListParamBean)
  82. {
  83. $url = "https://runion.meituan.com/api/orderList";
  84. $params = [
  85. "key"=>$orderListParamBean->getAppkey(),
  86. "ts"=>time(),
  87. "type"=>$orderListParamBean->getType(),
  88. "sign"=>"",
  89. "startTime"=>$orderListParamBean->getStartTime(),
  90. "endTime"=>$orderListParamBean->getEndTime(),
  91. "page"=>$orderListParamBean->getPage(),
  92. "limit"=>$orderListParamBean->getLimit(),
  93. "queryTimeType"=>$orderListParamBean->getQueryTimeType()
  94. ];
  95. $sign = self::generateSign($params);
  96. $params["sign"] = $sign;
  97. $res = HttpCurl::getCurl($url,$params);
  98. return $res;
  99. }
  100. /**
  101. * 生成小程序二维码
  102. * @param $sid string 推广为ID
  103. * @param $actId int 活动ID
  104. */
  105. public static function miniCode($sid,$actId)
  106. {
  107. $url = "https://runion.meituan.com/miniCode";
  108. $params = [
  109. "sid"=>$sid,
  110. "actId"=>$actId,
  111. "sign"=>""
  112. ];
  113. $sign = self::generateSign($params);
  114. $params["sign"] = $sign;
  115. $res = HttpCurl::getCurl($url,$params);
  116. return $res;
  117. }
  118. /**
  119. * 根据订单编号获取单个订单
  120. * @param $orderNumber string 订单编号
  121. * @param $key string 媒体appKey
  122. * @param $type string 订单类型
  123. */
  124. public static function queryOrderByOrderNumber($orderNumber,$key,$type)
  125. {
  126. $url = "https://runion.meituan.com/api/rtnotify";
  127. $params = [
  128. "key"=>$key,
  129. "oid"=>$orderNumber,
  130. "full"=>1,
  131. "type"=>$type,
  132. "sign"=>""
  133. ];
  134. $sign = self::generateSign($params);
  135. $params["sign"] = $sign;
  136. $res = HttpCurl::getCurl($url,$params);
  137. return $res;
  138. }
  139. /**
  140. * 获取美团推广链接
  141. * @param $userId string 用户ID
  142. * @param $spreadId string 推广位
  143. * @param $actId string 活动ID
  144. * @param $linkType string 链接类型
  145. */
  146. public static function getMeituanWaimaiUrl($userId, $spreadId, $actId, $linkType)
  147. {
  148. $key = "meituanUrl:".$userId."linktype:".$linkType."actid:".$actId;
  149. $val = self::getCacheFromRedis($key);
  150. if($val){
  151. return $val;
  152. }
  153. //不存在则从官方获取
  154. $val = self::generateLink($actId,$spreadId,$linkType,env("MEITUAN_LIANMENG_KEY"));
  155. self::setRedisCache($key,$val,0);
  156. return $val;
  157. }
  158. }