Commit 5f8b32781af23f5748150cd2fd9dbce2ed343ba6

Authored by 谭苏航
1 parent b1ed068f

chore: add debug logs to AuthService::getPhoneNumber

Showing 1 changed file with 16 additions and 3 deletions
@@ -190,7 +190,10 @@ class AuthService @@ -190,7 +190,10 @@ class AuthService
190 $appId = $this->config['wechat']['app_id']; 190 $appId = $this->config['wechat']['app_id'];
191 $appSecret = $this->config['wechat']['app_secret']; 191 $appSecret = $this->config['wechat']['app_secret'];
192 192
  193 + echo "Debug: Checking WeChat Config - AppID: {$appId}, SecretLen: " . strlen($appSecret) . "\n";
  194 +
193 if (empty($appId) || empty($appSecret)) { 195 if (empty($appId) || empty($appSecret)) {
  196 + echo "Debug: AppID or Secret is empty!\n";
194 return null; // 开发模式不支持 197 return null; // 开发模式不支持
195 } 198 }
196 199
@@ -200,25 +203,35 @@ class AuthService @@ -200,25 +203,35 @@ class AuthService
200 'appid' => $appId, 203 'appid' => $appId,
201 'secret' => $appSecret, 204 'secret' => $appSecret,
202 ]); 205 ]);
203 - $tokenRes = json_decode(file_get_contents($tokenUrl), true); 206 +
  207 + $tokenRaw = file_get_contents($tokenUrl);
  208 + echo "Debug: Access Token Raw Response: {$tokenRaw}\n";
  209 +
  210 + $tokenRes = json_decode($tokenRaw, true);
204 if (empty($tokenRes['access_token'])) { 211 if (empty($tokenRes['access_token'])) {
  212 + echo "Debug: Failed to get access token.\n";
205 return null; 213 return null;
206 } 214 }
207 215
208 // 2. 获取手机号 216 // 2. 获取手机号
209 $phoneUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" . $tokenRes['access_token']; 217 $phoneUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" . $tokenRes['access_token'];
210 - $phoneRes = json_decode(file_get_contents($phoneUrl, false, stream_context_create([ 218 + $phoneRaw = file_get_contents($phoneUrl, false, stream_context_create([
211 'http' => [ 219 'http' => [
212 'method' => 'POST', 220 'method' => 'POST',
213 'header' => 'Content-Type: application/json', 221 'header' => 'Content-Type: application/json',
214 'content' => json_encode(['code' => $phoneCode]) 222 'content' => json_encode(['code' => $phoneCode])
215 ] 223 ]
216 - ])), true); 224 + ]));
  225 +
  226 + echo "Debug: Phone Number Raw Response: {$phoneRaw}\n";
  227 +
  228 + $phoneRes = json_decode($phoneRaw, true);
217 229
218 if (isset($phoneRes['phone_info']['purePhoneNumber'])) { 230 if (isset($phoneRes['phone_info']['purePhoneNumber'])) {
219 return $phoneRes['phone_info']['purePhoneNumber']; 231 return $phoneRes['phone_info']['purePhoneNumber'];
220 } 232 }
221 233
  234 + echo "Debug: Failed to parse phone number from response.\n";
222 return null; 235 return null;
223 } 236 }
224 237
Please register or login to post a comment