1:ACCESS_TOKEN获取请求接口:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid的值&secret=secret的值
2:调用send接口的时候返回的了个48001错误
请求地址
POST https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=第一步请求获取的access_token值
{
"errcode": 48001,
"errmsg": "api unauthorized rid: 5f49bd4f-464f353e-13ccc870"
}
你写法不对,access_token替换为真的token了吗?另外 post的json主体呢?
具体文档,你仔细看下
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html#method-http
1:access_token获取调用接口:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}
通过请求上面的接口获取access_token,在下面接口请求中使用
2:https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}
这是我分两次请求的,
第二部请求的完整方法:
public string SubscribeMessage2(string touser)
{
try
{
AccessTokenModel AccessTokenModel = GetAccessToken2();//获取access_token
string _url = string.Format("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}", AccessTokenModel.access_token);
//json参数
var data = new
{
number01 = new { value = DateTime.Now.ToString("yyyyMMddhhmmss") },
date01 = new { value = DateTime.Now.ToString("yyyy年MM月dd日") },
site01 = new { value = "TIT创意园" },
site02 = new { value = "广州市新港中路397号" }
};
string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
{
touser = touser,//用戶openid
template_id = "jy4rnE36NHsUZYWE9KqrH2qEfDYc2sT22ewLo_gXaqk", // 模版template_id
data = data
});
var request = (HttpWebRequest)WebRequest.Create(_url);
request.Method = "POST";
request.ContentType = "application/json;charset=UTF-8";
byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
int length = byteData.Length;
request.ContentLength = length;
Stream writer = request.GetRequestStream();
writer.Write(byteData, 0, length);
writer.Close();
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
return responseString.ToString();
}
catch (Exception ex)
{
return ex.Message;
}
}
access_token用错了
{0} {1}都是我传递的参数
1:access_token获取调用接口:大神帮看下接口是否有错
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}
通过请求上面的接口获取access_token,在下面接口请求中使用
2:https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}
这是我分两次请求的,