|
|
@@ -136,4 +136,66 @@ class DeliveryController extends BaseController
|
|
|
//return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
|
|
|
return $this->redirect(['success']);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 授权回调接口
|
|
|
+ */
|
|
|
+ public function actionAuthCallback()
|
|
|
+ {
|
|
|
+ $callbackData = Yii::$app->request->post();
|
|
|
+ if (empty($callbackData)) {
|
|
|
+ $postStr = file_get_contents('php://input');
|
|
|
+ $callbackData = json_decode($postStr, true);
|
|
|
+ if (empty($callbackData)) {
|
|
|
+ util::fail('回调请求的数据为空');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从配置中获取安全token
|
|
|
+ // $token = Yii::$app->params['wx_intracity_token'] ?? 'your_token_here';
|
|
|
+ // $result = IntraCityExpress::handleOrderCallback($callbackData, $token);
|
|
|
+ // 记录回调日志
|
|
|
+ Yii::info('聚合配送回调:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'delivery');
|
|
|
+
|
|
|
+ $code = $callbackData['code'];
|
|
|
+ $state = $callbackData['state'];
|
|
|
+ $shopId = $callbackData['shopId'];
|
|
|
+ $isAllStoreAuth = $callbackData['isAllStoreAuth'];
|
|
|
+ $thirdStoreId = $callbackData['thirdStoreId'];
|
|
|
+ $storeId = $callbackData['storeId'];
|
|
|
+
|
|
|
+ // 验证state参数(防止CSRF)
|
|
|
+ //if ($state != $yourUserId) {
|
|
|
+ //throw new \yii\web\BadRequestHttpException('Invalid state parameter');
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 获取AccessToken
|
|
|
+ $auth = new \common\components\delivery\platform\shanSong\Auth();
|
|
|
+ $result = $auth->getAccessToken($code);
|
|
|
+
|
|
|
+ if (!$result['success']) {
|
|
|
+ throw new \yii\web\HttpException(500, '获取授权失败:' . $result['error']);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存授权信息到数据库
|
|
|
+ $data['user_id'] = $state;
|
|
|
+ $data['shop_id'] = $shopId;
|
|
|
+ $data['access_token'] = $result['access_token'];
|
|
|
+ $data['refresh_token'] = $result['refresh_token'];
|
|
|
+ $data['expires_at'] = time() + $result['expires_in'];
|
|
|
+ $data['auth_type'] = $isAllStoreAuth ? 'all_store' : 'single_store';
|
|
|
+
|
|
|
+ if (!$isAllStoreAuth) {
|
|
|
+ $data['third_store_id'] = $thirdStoreId;
|
|
|
+ $data['shans_store_id'] = $storeId;
|
|
|
+ }
|
|
|
+
|
|
|
+ ShansAuthTokenClass::add($data);
|
|
|
+ if (false) {
|
|
|
+ throw new \yii\web\HttpException(500, '保存授权信息失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
|
|
|
+ return $this->redirect(['success']);
|
|
|
+ }
|
|
|
}
|