string url2 = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + str1;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, url2);
var content = new StringContent("{\"code\":\"" + code + "\"}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
str2 = await response.Content.ReadAsStringAsync();
//注: 已经获取到access_token值了,使用postman访问https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + str1
(加json格式参数code)能获取到手机号数据。但是使用api代码时报错:{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest, could get access_token by getStableAccessToken, more details at https://mmbizurl.cn/s/JtxxFh33r ......
access_token 无效或者过期,别的地方重新获取了access_token,导致当前access_token过期了。
https://developers.weixin.qq.com/community/develop/article/doc/0000cc805683281d77a86435656013
string url2 = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + str1; var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, url2); var content = new StringContent("{\"code\":\"" + code + "\"}", null, "application/json"); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); str2 = await response.Content.ReadAsStringAsync(); //注: 已经获取到access_token值了,使用postman访问https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + str1 (加json格式参数code)能获取到手机号数据。但是使用api代码时报错:{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest, could get access_token by getStableAccessToken, more details at https://mmbizurl.cn/s/JtxxFh33r ......
//忘记将token值从json字符串提取出来,在以上访问api网址上面添加以下代码即可:
JObject jb1 = (JObject)JsonConvert.DeserializeObject(str1);
string str1 = jb1["access_token"].ToString();
-----问题已经解决!