集成微信公众号文档
This commit is contained in:
Spongebob5 2018-10-18 18:17:53 +08:00
parent b0d8c3bb70
commit a3308d1e51
11 changed files with 10 additions and 10 deletions

View file

@ -15,20 +15,20 @@ grammar_cjkRuby: true
项目botsharp-channel-weixin为腾讯微信BotSharp的通道模块加载此项目可以省去编写微信通道模块的过程当然也可以根据自己的需求去编写微信的通道模块。
项目文件botsharp-channel-weixin下载地址(https://github.com/Oceania2018/botsharp-channel-weixin)将botsharp-channel-weixin项目放置到BotSharp同级的目录下。加载botsharp-channel-weixin到BotSharp中。
![enter description here](./images/图片1_1.png)
![](./集成微信公众号图片/图片1.png)
右键点击“==依赖项==”、“==添加引用==”把botsharp-channel-weixin项目添加到BotSharp.WebHost的引用中。
![enter description here](./images/图片2.png)
![](./集成微信公众号图片/图片2.png)
找到BotSharp.WebHost下的app.json,修改moduleBasePath和botsharp-channel-weixin的Path路径。程序会根据路径找到其项目的.dll。
![enter description here](./images/图片3.png)
![](./集成微信公众号图片/图片3.png)
## 运行BotSharp
加载项目完毕运行BotSharp项目出现如下的黑色的控制台程序表示程序找到了botsharp-channel-weixin的.dll,项目运行成功。如果想用NLU做自然语言理解则可以加载botsharp-dialogflow项目到BotSharp中。
![运行结果](./images/BotSharp运行结果.png)
![](./集成微信公众号图片/BotSharp运行结果.png)
运行成功后,打开网址为(http://localhost:3112/index.html)的网页此网页所显示的为BotSharp的接口列表。
![enter description here](./images/3112.png)
![](./集成微信公众号图片/3112.png)
# 对接微信公众号
## 申请微信测试号
@ -38,29 +38,29 @@ grammar_cjkRuby: true
**1)申请服务器**
我们所要填写的url必须是外网能够访问到的服务器地址而且必须是80端口通过服务器的地址你要能够让微信访问到你的项目。
![enter description here](./images/微信接口配置信息1_1.png)
![](./集成微信公众号图片/微信接口配置信息1.png)
我们需要把内网映射出去变成能够访问的外网我们采取一个简单的方法通过ngrok进行内网穿透。ngrok工具的下载地址(http://ngrok.ciqiuwl.cn/)下载完成后解压缩。
找到apps.bat文件点击右键打开记事本进行编辑,执行 *ngrok -config=ngrok.cfg -subdomain xxx 80*//(xxx 是你自定义的域名前缀),如执行*ngrok -config=ngrok.cfg -subdomain sss 3112* ,双击弹出一个黑窗体,该黑窗体显示的域名就是映射出去的网址。
也有其它的方法得到外网网址,如通过路由器映射,可自行通过百度上网查询。
![enter description here](./images/ngrok黑窗体.png)
![](./集成微信公众号图片/ngrok黑窗体.png)
其中http://sss.ngrok.xiaomiqiu.cn即为映射的外网IP。
**2)填写接口配置信息**
url填写 http://外网IP/wx
Token自主设置这个token与公众平台wiki中常提的access_token不是一回事。这个token只用于验证开发者服务器。
![enter description here](./images/配置接口url.png)
![](./集成微信公众号图片/配置接口url.png)
Token是用于交互安全认证的可任意填写但要与服务端的校验微信的Controller一样。
打开BotSharp-Channel-Weixin类库下的Controllers文件中WeixinAsyncConreoller.cs类。正确填写Token、AppId字符串。其中Token要与微信测试号中的Token相同。
![enter description here](./images/配置接口Token.png)
![](./集成微信公众号图片/配置接口Token.png)
填写完毕打开ngrok并运行BotSharp项目则可以成功提交微信测试号的接口配置信息。
![enter description here](./images/接口配置成功.png)
![](./集成微信公众号图片/接口配置成功.png)
填写JS接口安全域名域名可随意填写。微信扫描关注测试公众号。
至此,集成微信公众号完成。

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB