当前位置:网站首页>Use Net core access wechat official account development
Use Net core access wechat official account development
2022-07-01 12:37:00 【Dotnet cross platform】
Part1 Preface
Recently, I want to write something based on .Net Core Articles developed by wechat official account
Part2 Test official account application
Test official account application address :https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
WeChat official account development document :https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html
You can enter the test number management page by scanning the authorization through wechat .
The test account has almost all official account interfaces , Individuals can only apply for subscription numbers , Few interfaces are available , And the number of message push will be limited . If you just do development testing , Then the test account is easier to use
Carry out interface configuration information
A server is required to conduct wechat authorization callback to the online domain name . But for no server , Or the students who first contact wechat official account development are a little unfriendly , Inconvenient for local debugging .
So I tried to debug local code through intranet penetration , Common tools are ngrok,FastTunnel, Peanut shell ,natapp wait
Part3 Development
newly build .Net Core webapi project , Map the local service to the external network
What the author uses here is natapp
Verify that the message does come from wechat server
We can easily write according to wechat development documents Wechat background “ Interface configuration information ”, There are four parameters
[HttpGet]
[ActionName("")]
public string Get(string signature, string timestamp, string nonce, string echostr)
{
}
Students who are obsessed with cleanliness may feel that there are four parameters , And then controller Receiving layers one by one will be particularly cumbersome . Then we can also use entity classes to accept parameters
[HttpGet]
[ActionName("")]
public string Get([FromUri] VxModel vxModel)
{
}
[FromUri] Property handles query parameters , namely "?" The subsequent key value pairs are URI in .
encryption / check
The process is as follows :
take token、timestamp、nonce Three parameters to sort lexicographically 2) Three parameter strings are spliced into a string sha1 encryption 3) Developers get encrypted strings that can be used with signature contrast , Identify that the request comes from wechat . If you confirm this GET Request from wechat server , Please return as is echostr Parameter contents .
Set wechat official account token, Defined as a constant , Used to verify
public const string Token = "weixin";
Then carry out signature verification according to the process
public static bool Check(string signature, string timestamp, string nonce)
{
string[] value = new string[3]
{
WeixinSetting.Token,
timestamp,
nonce
}.OrderBy(o=>o).ToArray();
string s = string.Join("", value);
byte[] array = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(s));
StringBuilder stringBuilder = new StringBuilder();
byte[] array2 = array;
foreach (byte b in array2)
{
stringBuilder.AppendFormat("{0:x2}", b);
}
return signature==stringBuilder.ToString();
}
The complete interface is as follows :
[HttpGet]
[ActionName("")]
public string Get(string signature, string timestamp, string nonce, string echostr)
{
if (CheckSignatureHelper.Check(signature, timestamp, nonce))
{
return echostr;
}
else
{
return " Check failed ";
}
}
In this way, the verification is successful .
边栏推荐
- Circular linked list--
- 腾讯黎巍:深耕“监管科技”,护航数字经济行稳致远
- Common chart usage of Bi tools
- Chapter 14 signals (IV) - examples of multi process tasks
- R语言基于h2o包构建二分类模型:使用h2o.gbm构建梯度提升机模型GBM、使用h2o.auc计算模型的AUC值
- JS related interview questions and answers (1)
- [datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
- 腾讯总考epoll, 很烦
- Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)
- Compile and debug net6 source code
猜你喜欢
logstash报错:Cannot reload pipeline, because the existing pipeline is not reloadable
[datawhale202206] pytorch recommendation system: precision model deepfm & DIN
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
Switch basic experiment
队列的链式存储
Ipv6-6to4 experiment
leetcode:226. 翻转二叉树【dfs翻转】
Chained storage of queues
[Suanli network] technological innovation of Suanli Network -- key technology of operation service
How to use opcache, an optimization acceleration component of PHP
随机推荐
First intention is the most important
用.Net Core接入微信公众号开发
哪个券商公司开户佣金低又安全又可靠
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
What are the solutions for session sharing of highly paid programmers & interview questions series 118?
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
leetcode:226. 翻转二叉树【dfs翻转】
Common chart usage of Bi tools
Teach you to complete the actual battle of image classification hand in hand -- Image Recognition Based on convolutional neural network
系统测试UI测试总结与问题(面试)
MySQL的零拷贝技术
MySQL common functions
Tencent security and KPMG released a regulatory technology white paper to analyze the "3+3" hot application scenarios
6.30 simulation summary
【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
简单斐波那契(递推)
MySQL workbench data modeling function
栈-------
Ansible Playbook
【语音信号处理】3语音信号可视化——prosody