Commit 5f8b32781af23f5748150cd2fd9dbce2ed343ba6
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 | 190 | $appId = $this->config['wechat']['app_id']; |
| 191 | 191 | $appSecret = $this->config['wechat']['app_secret']; |
| 192 | 192 | |
| 193 | + echo "Debug: Checking WeChat Config - AppID: {$appId}, SecretLen: " . strlen($appSecret) . "\n"; | |
| 194 | + | |
| 193 | 195 | if (empty($appId) || empty($appSecret)) { |
| 196 | + echo "Debug: AppID or Secret is empty!\n"; | |
| 194 | 197 | return null; // 开发模式不支持 |
| 195 | 198 | } |
| 196 | 199 | |
| ... | ... | @@ -200,25 +203,35 @@ class AuthService |
| 200 | 203 | 'appid' => $appId, |
| 201 | 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 | 211 | if (empty($tokenRes['access_token'])) { |
| 212 | + echo "Debug: Failed to get access token.\n"; | |
| 205 | 213 | return null; |
| 206 | 214 | } |
| 207 | 215 | |
| 208 | 216 | // 2. 获取手机号 |
| 209 | 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 | 219 | 'http' => [ |
| 212 | 220 | 'method' => 'POST', |
| 213 | 221 | 'header' => 'Content-Type: application/json', |
| 214 | 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 | 230 | if (isset($phoneRes['phone_info']['purePhoneNumber'])) { |
| 219 | 231 | return $phoneRes['phone_info']['purePhoneNumber']; |
| 220 | 232 | } |
| 221 | 233 | |
| 234 | + echo "Debug: Failed to parse phone number from response.\n"; | |
| 222 | 235 | return null; |
| 223 | 236 | } |
| 224 | 237 | ... | ... |
Please
register
or
login
to post a comment