80 行
3.5 KiB
PHP
可执行文件
80 行
3.5 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace NotifyApi\Controller;
|
|
|
|
use Think\Controller;
|
|
//[1.3.89]
|
|
/**
|
|
* 菜鸟物流云回调
|
|
* Class CNLogisticsController
|
|
* @package NotifyApi\Controller
|
|
*/
|
|
class CNLogisticsController extends Controller
|
|
{
|
|
public function auth_callback()
|
|
{
|
|
$accessCode = I('get.accessCode');
|
|
$ext = I('get.ext');
|
|
$appKey = I('get.appkey');
|
|
$status = false;
|
|
if ($appKey == C('CN_APP_KEY') && !empty($accessCode) && !empty($ext)) {
|
|
$arr = explode(':', $ext);
|
|
if (count($arr) == 2) {
|
|
$typeArr = explode('/', $arr[0]);
|
|
$infoArr = explode('/', $arr[1]);
|
|
if ($typeArr[0] == 'type' && in_array($typeArr[1], array('1', '2')) && $infoArr[0] == 'id') {
|
|
//请求正确
|
|
$auth_type = $typeArr[1];//1商户授权 2门店授权
|
|
$s_key = $infoArr[1];//存储id的s缓存键名
|
|
$id = S($s_key);
|
|
if (!empty($id)) {
|
|
//获取accessToken
|
|
$sign = md5($accessCode . "," . $appKey . "," . C('CN_APP_SECRET'));;//签名
|
|
$url = "http://lcp.cloud.cainiao.com/api/permission/exchangeToken.do?accessCode={$accessCode}&isvAppKey={$appKey}&sign={$sign}";
|
|
$res = file_get_contents($url);
|
|
$res = json_decode($res, true);
|
|
if ($res && $res['success'] == true) {
|
|
$accessToken = $res['accessTokens'][0]['accessToken'];
|
|
$update = false;
|
|
if ($auth_type == 2) {
|
|
//门店授权
|
|
$StoreConfigModel = D('StoreConfig');
|
|
$map = array(
|
|
'store_id' => $id,
|
|
);
|
|
$old = $StoreConfigModel->getFind($map);
|
|
$item = array(
|
|
'cn_token' => $accessToken
|
|
);
|
|
if (!empty($old)) {
|
|
//判断是否有数据
|
|
if ($old['cn_token'] == $accessToken) {
|
|
$update = true;
|
|
} else {
|
|
$update = $StoreConfigModel->updateOrder($map, $item);
|
|
}
|
|
} else {
|
|
$item['store_id'] = $id;
|
|
$update = $StoreConfigModel->addOrder($item);
|
|
}
|
|
}
|
|
if ($update) {
|
|
$status = true;
|
|
$msg = '授权成功';
|
|
} else {
|
|
$msg = '数据库更新错误,请重试';
|
|
}
|
|
} else {
|
|
$msg = 'accessToken获取失败,请重试';
|
|
}
|
|
} else {
|
|
$msg = '请求已过期,请重新扫码授权';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$this->assign('status', $status);
|
|
$this->assign('msg', $msg ? $msg : '您的请求有误');
|
|
$this->display();
|
|
}
|
|
} |