当前位置:网站首页>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 .
边栏推荐
- 【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
- 79. 单词搜索【dfs + 回溯visit + 遍历起点】
- JS related interview questions and answers (1)
- kubernetes之ingress探索实践
- Chained storage of queues
- Leetcode (Sword finger offer) - 58 - ii Rotate string left
- 网络socket的状态要怎么统计?
- Application of stack -- bracket matching problem
- Ansible Playbook
- CPI tutorial - asynchronous interface creation and use
猜你喜欢

手机便签应用

基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
![[106] 360 check font - check whether the copyright of local Fonts is commercially available](/img/a7/615e8000647b56f03a6a1d3dd81b6d.jpg)
[106] 360 check font - check whether the copyright of local Fonts is commercially available

79. 单词搜索【dfs + 回溯visit + 遍历起点】

MySQL workbench data modeling function

JS reverse | m3u8 data decryption of a spring and autumn network

Mobile note application

A hole in solder paste

ROS2 Foxy depthai_ros教程

【语音信号处理】3语音信号可视化——prosody
随机推荐
kubernetes之ingress探索实践
Ansible Playbook
Friends day 2022
【20211129】Jupyter Notebook遠程服務器配置
【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
Mobile note application
Application of stack -- bracket matching problem
6.30模拟赛总结
[JS] interview questions
微信小程序 – 80个实用的微信小程序项目实例
Switch basic experiment
[Maui] add click events for label, image and other controls
Tencent Li Wei: deeply cultivate "regulatory technology" to escort the steady and long-term development of the digital economy
Blocking sockets的读写操作该怎么玩?
Ansible相关内容梳理
The difference between memcpy and strcpy
Share several tools for designing exquisite circuit diagrams
Compile and debug net6 source code
What are the PHP FPM configuration parameters
IOS interview