• [微信小程序]向指定用户推送模版消息(c#代码)亲测可用


    调用:SubscribeMessageToUser("用户openid字符串");
    官方比较坑:限制必须点击授权按钮的时候才能执行否则就会提示:
    {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 5f66d001-785045b2-5443a9f9"}
    翻译解释为:用户拒绝接收信息

    小程序向指定用户推送模版消息(c#代码)      [HttpPost] public JsonResult SubscribeMessageToUser(string openid, string title=null, string content=null) { AjaxResult res = new AjaxResult(); res.state = false; try { AccessTokenModel AccessTokenModel = xcx_Get_Token();//获取access_token string _url = string.Format("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}", AccessTokenModel.access_token); //json参数 string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new { touser = openid,//用戶openid template_id = "模版ID", // 模版template_id page = "pages/index/index", //miniprogram_state = "developer", lang = "zh_CN", data = new { thing1 = new { value = "签到提醒" }, time5 = new { value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") }, thing2 = new { value = "点击签到" } } }); 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(); JavaScriptSerializer js = new JavaScriptSerializer(); //实例化一个能够序列化数据的类 AccessTokenModel_Err ErrInfo = js.Deserialize<AccessTokenModel_Err>(responseString); //AccessTokenModel_Err ErrInfo = (AccessTokenModel_Err)JsonConvert.DeserializeObject(responseString); res.message = ErrInfo.errmsg; if(ErrInfo.errcode==0) res.state = true; //return responseString.ToString(); } catch (Exception ex) { res.state = false; res.message = ex.Message; } return Json(res, JsonRequestBehavior.AllowGet); }

      

  • 相关阅读:
    boost::asio 连接管理11 如何关闭连接
    boost::asio async_write也不能保证一次发完所有数据 二
    boost::asio async_write也不能保证一次发完所有数据 一
    boost参考博客
    C++ 多线程编程总结
    Boost::asio io_service 实现分析
    使用boost io_service时,需要注意的东西
    Boost::Thread 多线程的基础知识
    boost::thread类
    Boost::thread库的使用
  • 原文地址:https://www.cnblogs.com/romanticcrystal/p/13699290.html
Copyright © 2020-2023  润新知