概述
接入微信公眾平台開發,開發者需要按照如下步驟完成:
- 填寫服務器配置
- 驗證服務器地址的有效性
- 依據接口文檔實現業務邏輯
- 官方指南文檔
服務器配置
- 服務器地址(URL):填寫完
URL
后,微信服務器會發送GET
請求,並攜帶以下參數:signature
:微信加密簽名timestamp
:時間戳nonce
:隨機數echostr
:隨機字符串
- 令牌(Token):用於加密簽名的密鑰
ASP.NET API業務邏輯解決方案
比如我在微信公眾平台服務器配置中進行如下配置:
- 服務器地址(URL):https://mptest.niansi.com/api/mp
- 令牌(Token):huayueniansi
[Route("api/[controller]")]
[ApiController]
public class MPController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get(string signature, string timestamp, string nonce, string echostr)
{
string[] tmpArr = { "huayueniansi", timestamp, nonce };
Array.Sort(tmpArr);// 字典排序
string tmpStr = string.Join("", tmpArr);
tmpStr = SHA1Helper.SHA1Crypto(tmpStr);
tmpStr = tmpStr.ToLower();
if (tmpStr == signature && !string.IsNullOrWhiteSpace(echostr))
return echostr;
return "";
}
}