C # Development of WeChat applet send template message function

Source: Internet
Author: User
Tags openid
This article mainly introduces the C # development of small program send template message function, the need for friends can refer to the following

Step one: Get the template ID

There are two ways to get a template ID

    1. Get the template ID from the template message management interface

    2. Manually configure get template ID on public platform

Step two: The <form/> component of the page, when the property Report-submit is true, can be declared as the need to send a template message, click the button submit form can get formid, for sending template messages. Or when the user completes the payment behavior, you can get prepay_id used to send the template message.

Step three: Call the interface issued template message

Today it is important to say the third step how to achieve, the previous steps are relatively simple to skip.

----------------------------------------------------------------------------------------------------

1. Get Access_token

Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

The Access_token will be used later when sending the template message

2. Send template messages

Interface Address: (Access_token need to be replaced by the Access_token obtained above)

Https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN

Note: Since the developer is now not allowed to use the Https://api.weixin.qq.com interface directly on the front-end to obtain data, the following operations must be done by the server background.

Official Post parameters:

{"Touser": "OPENID", "template_id": "template_id", "page": "Index", "form_id": "FORMID", "data": {"Keyword1": {  "Value": "339208499", "Color": "#173177"}, "Keyword2": {"value": "January 05, 2015", "Color": "#173177" }, "Keyword3": {"value": "Sheraton Guangzhou Hotel", "Color": "#173177"}, "Keyword4": {"value": "Guangzhou Tianhe District Tianhe Road No. 208", "Color" : "#173177"}, "Emphasis_keyword": "Keyword1."   DATA "} var l =" https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token= "+ access_token; var tempdata = new {Touser = OpenID, template_id = "verash9plzmyw9-pqjiggkbca3hou30qfvtaxd******",//This is 1, Application template message I      D, page = "Pages/index/index", form_id = formId, data = new {Keyword1 = new {value = title,  color = "#666666"}, Keyword2 = new {value = DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss"), color = "#9b9b9b"}, Keyword3 = new {value = Remarks, color = "#9b9b9b"}}, COlor = "#666666"};   X.component.tools.webclient WC = new X.component.tools.webclient (); var result = Tempdata.tojson ();   Newtonsoft.Json.JsonConvert.SerializeObject (TempData); Wc.   Encoding = System.Text.Encoding.UTF8; var obj = WC. Post (l, result); Get the results returned

Note the page path

The result of the last return:

{"Data": {  "Success": true},  "StatusCode": $,  "header": {  "Server": "microsoft-iis/7.5",   " Access-control-allow-origin ":" Https://pubchem.ncbi.nlm.nih.gov ",   " Cache-control ":" Private ",   " X-ua-compatible ":" Chrome=1 ",   " Date ":" Thu, Sep 04:46:34 GMT ",   " x-aspnetmvc-version ":" 4.0 ",   " Content-type ":" Application/json; Charset=utf-8 ",   " x-powered-by ":" ASP. ",   " x-aspnet-version ":" 4.0.30319 ",   " Content-length ":" 16 " },  "ErrMsg": "Request:ok"}

Effect:

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.