300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 微信开发服务器验证配置 c#微信公众号开发----基本设置 服务器配置token验证...

微信开发服务器验证配置 c#微信公众号开发----基本设置 服务器配置token验证...

时间:2022-02-24 08:11:14

相关推荐

微信开发服务器验证配置 c#微信公众号开发----基本设置 服务器配置token验证...

c#微信公众号开发----基本设置

参考微信官方文档

https://developers./doc/offiaccount/basic_information/access_overview.html

开发→基本配置

公众号开发信息

注:1.记录好开发者密码,会在程序中验证过程中使用到。

2.通过appid和appsecret调用access_token时,至有在ip白名单的ip才能成功调用。

服务器配置

若此处开启服务器配置,设置的自动回复和自定义菜单将全部失效。必须在程序中重写相关方法。

点击修改配置,token为随意填写的参数

我是用的是一般处理程序编写的微信接口token验证,参数参考官方文档。代码如下:

开发者通过检验signature对请求进行校验。若确认此次get请求来自微信服务器,请原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败。加密/校验流程如下:

1)将token、timestamp、nonce三个参数进行字典序排序

2)将三个参数字符串拼接成一个字符串进行sha1加密

3)开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。

1 public void processrequest(httpcontext context){

2 //验证token

3 string poststring = string.empty;

4 string token ="aabbcc"; //验证token,随意填写

5 if(string.isnullempty(token)){

6 return ;

7 }

8 string echostring = httpcontext.current.request.querystring["echostr"];

9 string signature = httpcontext.current.request.querystring["sianature"];

10 string timestamp = httpcontext.current.request.querystring["timestamp"];

11 string nonce = httpcontext.current.request.querystring["nonce"];

12 if(checksignature(token,signature,timestamp,nonce)){

13 if(!string.isnullorempty(echistring)){

14 httpcontext.current.response.write(echostring);

15 httpcontext.current.response.end();

16 }

17 }

18 }

1 ///

2 /// 验证微信签名

3 ///

4 /// token

5 /// 签名

6 /// 时间戳

7 /// 随机数

8 ///

9 public static bool checksignature(string token,

10 string signature, string timestamp, string nonce)

11 {

12 string[] arrtmp = { token, timestamp, nonce };

13 //字典排序

14 array.sort(arrtmp);

15 //拼接

16 string tmpstr = string.join("", arrtmp);

17 //sha1验证

18 tmpstr = formsauthentication.hashpasswordforstoringinconfigfile(tmpstr, "sha1");

19 //tmpstr = membership.createuser(tmpstr, "sha1");

20 tmpstr = tmpstr.tolower();

21

22 if (tmpstr == signature)

23 {

24 return true;

25 }

26 else

27 {

28 return false;

29 }

30 }

将编写的代码路径,填写到url里,前面填写的“aabbcc”,此时token里填写的也必须为“aabbcc”。

token必须保持一致,若不一致会弹出提示。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。