123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace App\Http\Utils\Meituan;
- use App\Exceptions\CommonException;
- use App\Http\Bean\Util\Meituan\CouponListParamBean;
- use App\Http\Bean\Util\Meituan\OrderListParamBean;
- use App\Http\Enum\ErrorEnum;
- use App\Http\Enum\MeiTuanLinkTypeEnum;
- use App\Http\Utils\BaseUtil;
- use Tool\ShanTaoTool\HttpCurl;
- class MeituanLianmengUtil extends BaseUtil
- {
- /**
- * 生成sign
- * @param $params array 参数
- * @return string
- */
- public static function generateSign($params)
- {
- $secret = env("MEITUAN_LIANMENG_SECRET");
- unset($params["sign"]);
- ksort($params);
- $str = $secret; // $secret为分配的密钥
- foreach($params as $key => $value) {
- $str .= $key . $value;
- }
- $str .= $secret;
- $sign = md5($str);
- return $sign;
- }
- /**
- * @param $actId int 活动id,可以在联盟活动列表中查看获取
- * @param $sid string 推广位ID
- * @param $linkType int 链接类型(1、h5链接2、deeplink(唤起)链接3、中间页唤起链接4、微信小程序唤起路径)
- * @param $appkey string appkey
- */
- public static function generateLink($actId,$sid,$linkType,$appkey)
- {
- $url = "https://runion.meituan.com/generateLink";
- $params = [
- "actId"=>$actId,
- "key"=>$appkey,
- "sid"=>$sid,
- "linkType"=>$linkType,
- "sign"=>""
- ];
- $sign = self::generateSign($params);
- $params["sign"] = $sign;
- $res = HttpCurl::getCurl($url,$params);
- if($res["status"]!=0){
- throw new CommonException(ErrorEnum::ERROR_MEITUAN_LINK);
- }
- return $res["data"];
- }
- /**
- * 领券结果查询接口
- * @param CouponListParamBean $couponListParamBean
- */
- public static function couponList(CouponListParamBean $couponListParamBean)
- {
- $url = "https://runion.meituan.com/api/couponList";
- $params = [
- "key"=>$couponListParamBean->getAppkey(),
- "ts"=>time(),
- "type"=>$couponListParamBean->getType(),
- "sign"=>"",
- "startTime"=>$couponListParamBean->getStartTime(),
- "endTime"=>$couponListParamBean->getEndTime(),
- "page"=>$couponListParamBean->getPage(),
- "limit"=>$couponListParamBean->getLimit(),
- "sid"=>$couponListParamBean->getSid()
- ];
- $sign = self::generateSign($params);
- $params["sign"] = $sign;
- $res = HttpCurl::getCurl($url,$params);
- return $res;
- }
- /**
- * 获取订单列表接口
- * @param OrderListParamBean $orderListParamBean
- */
- public static function orderList(OrderListParamBean $orderListParamBean)
- {
- $url = "https://runion.meituan.com/api/orderList";
- $params = [
- "key"=>$orderListParamBean->getAppkey(),
- "ts"=>time(),
- "type"=>$orderListParamBean->getType(),
- "sign"=>"",
- "startTime"=>$orderListParamBean->getStartTime(),
- "endTime"=>$orderListParamBean->getEndTime(),
- "page"=>$orderListParamBean->getPage(),
- "limit"=>$orderListParamBean->getLimit(),
- "queryTimeType"=>$orderListParamBean->getQueryTimeType()
- ];
- $sign = self::generateSign($params);
- $params["sign"] = $sign;
- $res = HttpCurl::getCurl($url,$params);
- return $res;
- }
- /**
- * 生成小程序二维码
- * @param $sid string 推广为ID
- * @param $actId int 活动ID
- */
- public static function miniCode($sid,$actId)
- {
- $url = "https://runion.meituan.com/miniCode";
- $params = [
- "sid"=>$sid,
- "actId"=>$actId,
- "sign"=>""
- ];
- $sign = self::generateSign($params);
- $params["sign"] = $sign;
- $res = HttpCurl::getCurl($url,$params);
- return $res;
- }
- /**
- * 根据订单编号获取单个订单
- * @param $orderNumber string 订单编号
- * @param $key string 媒体appKey
- * @param $type string 订单类型
- */
- public static function queryOrderByOrderNumber($orderNumber,$key,$type)
- {
- $url = "https://runion.meituan.com/api/rtnotify";
- $params = [
- "key"=>$key,
- "oid"=>$orderNumber,
- "full"=>1,
- "type"=>$type,
- "sign"=>""
- ];
- $sign = self::generateSign($params);
- $params["sign"] = $sign;
- $res = HttpCurl::getCurl($url,$params);
- return $res;
- }
- /**
- * 获取美团推广链接
- * @param $userId string 用户ID
- * @param $spreadId string 推广位
- * @param $actId string 活动ID
- * @param $linkType string 链接类型
- */
- public static function getMeituanWaimaiUrl($userId, $spreadId, $actId, $linkType)
- {
- $key = "meituanUrl:".$userId."linktype:".$linkType."actid:".$actId;
- $val = self::getCacheFromRedis($key);
- if($val){
- return $val;
- }
- //不存在则从官方获取
- $val = self::generateLink($actId,$spreadId,$linkType,env("MEITUAN_LIANMENG_KEY"));
- self::setRedisCache($key,$val,0);
- return $val;
- }
- }
|