他居然没有php的sdk!也不像饿了么提供授权地址,授权完成直接把相关信息提交到回调地址。
门店映射接入参数
https://developer.meituan.com/openapi#4.1.2
数字签名sign
https://developer.meituan.com/openapi#3.2
sign签名验证
https://developer.meituan.com/admin#/sign/tool
developerId和SignKey
获取地址https://developer.meituan.com/admin#/record/account
在sign生成文档已知。
1、将请求参数中除sign外的多个键值对,根据键按照字典序排序,并按照"key1value1key2value2..."的格式拼成一个字符串。
2、将signKey拼接在1中排序后的字符串前面得到待签名字符串。
3、使用sha1算法加密待加密字符串并转为小写即为sign。
//封装sign计算
function meituan_sign($arr)
{
ksort($arr);
$str = '';
foreach ($arr as $k=>$v) {
$str .= $k . $v;
}
$SignKey = '';
return sha1($SignKey.$str);
}
$timestamp = time();
$ePoiId = 7465;//本地商户ID
$businessId = 2;//外卖业务
$developerId = ;
$arr['charset'] = 'utf-8';
$arr['developerId'] = $developerId;
$arr['businessId'] = $businessId;
$arr['ePoiId'] = $ePoiId;
$arr['timestamp'] = $timestamp;
$sign = meituan_sign($arr);
$url = 'https://open-erp.meituan.com/storemap?developerId='.$developerId.'&businessId='.$businessId.'&ePoiId='.$ePoiId.'×tamp=' . $timestamp . '&sign='.$sign.'&charset=utf-8';
Header("Location:$url");
exit;
疑似bug
生成的授权链接是有 &charset=utf-8 参数的,打开跳转到登录页面后,参数丢失。登录的话会出现获取门店出错(3),验证签名失败。
解决方法就是手动补齐这个参数,再刷新页面进行登录。
完成操作之后,打开
门店映射回调地址测试
https://developer.meituan.com/admin#/callback/tool
授权成功后会把数据post提交到回调地址
header("Content-type:text/html; charset=utf8");
$data = file_get_contents("php://input");
parse_str($data, $arr);
if (!empty($data) && !empty($arr)) {
$sql['token'] = $arr['appAuthToken'];
$sql['id'] = $arr['ePoiId'];
}
echo '{"data":"success"}';