希望在微信里给APP的用户发消息


首先获取用户授权



成功后在手机上通过接口

 https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=13_yr-U5T9Z7sD9wK8t-b6CLlF37ptdzeeqWrqlM1_7ShilbZvJzofZyY97bqa30rg0M2MiJMHeJk0euVfexnN2M0rFCdREVo3S7S5bFKWcWzU

向微信API post数据

{"touser":"oKn3lvkut8w-H0oM2c-3Rhsqx70o",

"template_id":"k5dLFam6GtlfptCMkbR02eqIeO22oNqn8SaL1bSSuc4",

"url":"https:\/\/mp.weixin.qq.com\/s\/Ojd9nmggEPeLHHK1tJKGrQ",

"scene":1,

"title":"Hello world",

"data":{"content":{"value":"data","color":"#ff0000"}}

}


结果报错

{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [o8Y_mA0765vr47!]"}



不知道是什么原因?

其中openid和access_token通过接口

 String uri = String.format("https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s", weixinAccessToken, openId);

验证通过。为什么还会报错?



代码

        String verifyUri = String.format("https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s", weixinAccessToken, openId);
String subscribeUri = "https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=" + weixinAccessToken;

HttpsURLConnection urlConnection = null;

try {
// verify access token

           Log.d(TAG, "verify uri = " + verifyUri);
URL verifyUrL = new URL(verifyUri);
urlConnection = (HttpsURLConnection) verifyUrL.openConnection();

{
InputStream in1 = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader r = new BufferedReader(new
展开全部
收起
2回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • 万发财

    12人对此回答表示赞同

    错误信息已经提示:凭证无效,access_token无效或不是最新的

    展开
    12
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Brayden

    9人对此回答表示赞同

    当然是最新的,刚刚微信登录以后获取的凭证。而且

    展开
    9
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部