MeituanLianmengUtil.php 4.5 KB

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