
微信发送模板信息
配置成功后应该是这样的:
发布日期:2021-05-08 22:13:20
浏览次数:30
分类:精选文章
本文共 1749 字,大约阅读时间需要 5 分钟。
//MVC实现接口
public ActionResult templateInfo() { HttpClient httpClient = new HttpClient(); var tempobj = new { touser = "oqDCQuFzcFQYZyEvr2RJCtoCo-cQ", //`这里是你要发送的用户关注你微信号` template_id = "Y3bIKrzDq2Xi_qwLowq0libdWiRdAwtYuj8wCHFr3ss",//这个是你新增模板测试的模板ID 主要操作看下图 data = new { prodction = new { value = "毒品(卡洛因)", color = "red" }, price = new { value = "2239.8元", color = "#173177" }, time = new { value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), color = "#173177" }, because = new { value = "根据官方调查,你在重庆沙坪坝区有贩卖毒品现象,请尽快迷途知返,自来自首,不然后果自负!", color = "#245232" }, remark = new { value = "说出同伙,可减免犯罪有期徒刑,还请保重!", color = "red" } } }; string jsonstr = JsonConvert.SerializeObject(tempobj); StringContent stringContent = new StringContent(jsonstr); string result = httpClient.PostAsync("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + Access_token.Gettoken(), stringContent).Result.Content.ReadAsStringAsync().Result; return Json(result, JsonRequestBehavior.AllowGet); }
主要遇到的一些问题:
配置过程中的问题: