|
|
@@ -52,9 +52,11 @@ class Auth
|
|
|
// 测试环境配置
|
|
|
$this->appKey = 'dadaf2279d901a5ba40';
|
|
|
$this->appSecret = '828a03677a1c00a3a5b3c59209c4433d';
|
|
|
- $this->redirectUri = Yii::$app->params['ghsHost'].'/delivery/dada-auth-callback';
|
|
|
- $this->authorizeUrl = self::AUTHORIZE_URL_TEST;
|
|
|
- $this->tokenUrl = self::TOKEN_URL_TEST;
|
|
|
+ $this->redirectUri = Yii::$app->params['ghsHost'].'/delivery/dada-auth-callback?mainId='.$mainId;
|
|
|
+ // $this->authorizeUrl = self::AUTHORIZE_URL_TEST; // TODO 测试环境需要单独申请测试商户
|
|
|
+ // $this->tokenUrl = self::TOKEN_URL_TEST;
|
|
|
+ $this->authorizeUrl = self::AUTHORIZE_URL_PROD;
|
|
|
+ $this->tokenUrl = self::TOKEN_URL_PROD;
|
|
|
}
|
|
|
|
|
|
$this->isSandbox = !$isProduction;
|
|
|
@@ -99,7 +101,7 @@ class Auth
|
|
|
if (!empty($params)) {
|
|
|
$requestUrl .= '?' . http_build_query($params);
|
|
|
}
|
|
|
- Yii::info("\n\n\n\n\n\nrequestUrl: " . $requestUrl);
|
|
|
+ Yii::info('达达获取ticket requestUrl: ' . $requestUrl);
|
|
|
|
|
|
// 初始化 cURL
|
|
|
$ch = curl_init();
|
|
|
@@ -111,13 +113,15 @@ class Auth
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_USERAGENT, 'huahuibao-dada-auth');
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
- 'Content-Type: application/json'
|
|
|
+ 'Accept: application/json',
|
|
|
]);
|
|
|
|
|
|
// 执行请求
|
|
|
$response = curl_exec($ch);
|
|
|
$error = curl_error($ch);
|
|
|
+ $httpCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
curl_close($ch);
|
|
|
|
|
|
// 检查错误
|
|
|
@@ -125,11 +129,14 @@ class Auth
|
|
|
throw new \Exception('cURL Request Error: ' . $error);
|
|
|
}
|
|
|
|
|
|
+ if ($httpCode !== 200) {
|
|
|
+ Yii::error('达达获取ticket HTTP失败: httpCode=' . $httpCode . ' response=' . $response);
|
|
|
+ util::fail('请求达达获取ticket失败');
|
|
|
+ }
|
|
|
+
|
|
|
// 解析响应
|
|
|
$resp = json_decode($response, true);
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
- // 如果解析失败,可能是非 JSON 响应
|
|
|
- // throw new \Exception('Invalid JSON Response: ' . $response);
|
|
|
Yii::error('Invalid JSON Response: ' . $response);
|
|
|
util::fail('请求达达获取ticket失败');
|
|
|
}
|