Tutorial on the use of Bee.WeiXin WeChat framework
Let’s take a look at how to develop the WeChat public platform through Bee.WeiXin. Regarding the general introduction of WeChat public platform, I will not go into details here. Just look for it in the garden. This article mainly introduces Bee.WeXin, and the code has been published to beeweixin.codeplex.com/.
BeeWeiXin is a development framework developed for Tencent’s WeChat public platform. This project is developed based on Bee OPOA Platform.
Contains the following functions:
1. WeChat reply model based on call tree. The call tree supports multi-level (with context) responses, and can respond in three ways: text, graphics, and custom. Among them, you can customize the three methods (text, graphics, music) provided by the WeChat public platform API.
2. Provides the function of synchronizing the WeChat following user list.
3. Provides menu management function.
4. Provides image and text management functions.
5. Natively integrate all functions on Bee OPOA Platform, mainly Permission management.
About Debugging, it is recommended to use the tools provided by garden friends WeChat public account to develop and release debugging tools
Preview
Configuration item description
Configuration items are all configured in [appSettings] in web.config.
[WeiXinToken] is the public platform API token;
[Debug] is Indicates whether it is currently in debugging mode. The difference between debugging mode and non-debugging mode is whether the initiated call is verified.
[WeiXinUserName] and [WeiXinPassword] are required for [Resynchronize All Users] in the menu [WeChat Follow Users]. Log in the simulated web page to the WeChat public platform, and then obtain the user list information. If it is not needed, you can ignore it or hide this menu.
[WeiXinAppId] and [WeiXinAppSec] are required in the menu [WeChat Menu Management], which can manage the menu of WeChat public accounts. Of course, this tool [WeChat Public Account Development and Debugging Tool Release] also has this function, which is more convenient. If it is not needed, you can ignore it or hide this menu.
[WeiXinController] is the default system response Controller. Please refer to the code for specific logic.
Response in call chain mode
The call chain is based on context. There is an option in the configuration item [Whether to enter the call chain]. If so, this response will be added to the call chain. to form context. For example, [Menu 1] needs to enter the call chain, otherwise the sub-items under this item will not respond.
First look at the following pictures:
From the preview picture, you can intuitively understand that the call chain can provide three types of responses: text, graphics, and customization.
Text is a general text response. For example, [Menu 1] has been configured in the Bee.WeiXinDemo project to respond with text, and the node value is V1001_M1_1.
回复1,test1 回复2,test2 回复3,test3
The reply is as follows:
#The image and text are the image and text information provided in the WeChat public platform API, configured in the call chain Just enter the specified article numbers in order [this number is the ID in WeChat article management] (separated by commas).
For example, test2 under [Menu 1] is in graphic and text format. To enter test2, you need to trigger menu 1 first, and then trigger test2. As shown below:
Customization is integrated into the Bee OPOA Platform frameworkMVC . Therefore, the configuration is also implemented through Controller, Action.
For example, test3 under [Menu 1] is a custom method. To enter test3, you need to trigger menu 1 first, and then trigger test3. As shown below:
I don’t know if you understand it? It is recommended that you download the source code and debug it to deepen your understanding. It is best to take a look at the code when you have time to help improve the project, haha.
[Menu 1] only has key values [1], [2], and [3]. How should the user respond if he inputs something else? At this time, you only need to configure the key value [*] as a response to other configuration items.
理解调用链上下文
在这种基于调用链的应答中, 上下文是必要的。 怎么理解呢?举例说明吧:我要查询某个产品的某个国家的最近3个月的销售情况。 由于微信平台的特性, 我们不可能像其他应用给用户以直观的查询。
我们只有采用引导式的方式去引导用户得到她想要的结果。 设计的菜单如预览图中【多级菜单】项所示。具体的配置项如下图:
当用户点击菜单按钮触发了【V1001_M1_2】的事件, 系统响应提示文本【上图的1】; 用户根据提示, 选择产品, 输入1, 系统提示输入国家【上图的2】。 由于国家太多, 不太可能配置所有国家的选项, 所有采用了一个通配符的方案【上图的3】, 并采用自定义的方式应答。 代码如下:
public WeiXinTextResult CheckCountry() { string content = ViewData.TryGetValue<string>("content", string.Empty); // 验证输入的国家是否合法 bool validFlag = content.IndexOf("CN") >= 0; if (validFlag) { return WeiXinText("1 最近3个月销售统计\r\n2 最近6个月销售统计"); } else { // 由于调用链有上下文, 用户输入错误, 需要将当前应答取消。Current.MessageStack.Pop(); Current.MessageStack.Pop(); return WeiXinText("国家不合法,请重新输入国家。"); } }
由以上代码可以知道上下文可以通过Current.MessageStack获取。
用户输入正确的国家代码, 则引导用户做下一个选择.
自定义MVC响应
这个基本上跟Bee OPOA Platform的方式一模一样。 如【菜单1】下的【Other】项的响应就是采用该方式的。代码如下:
public ActionResult Other() { return View(); }
View代码如下:
<%@ Page Language="C#" AutoEventWireup="false" Inherits="Bee.Web.BeePageView" %> <%@ Import Namespace="Bee.Web" %> <%@ Import Namespace="Bee" %> <%@ Import Namespace="System.Collections.Generic" %> <xml> <ToUserName><![CDATA[<%=ViewData["FromUserName"] %>]]></ToUserName> <FromUserName><![CDATA[<%=ViewData["ToUserName"] %>]]></FromUserName> <CreateTime><%=Bee.WeiXin.DateTimeUtil.GetWeixinDateTime(DateTime.Now) %></CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content>回复1 联系方式 回复2 在线咨询</Content> </xml>
框架基类 Bee.WeiXin.Controller.WeiXinControllerBase提供了微信公众平台API所对应的三种响应的ActionResult, 具体请查看源码.
【相关推荐】
1. 微信公众号平台源码下载
2. 微智创T+微信机器人源码
The above is the detailed content of Tutorial on the use of Bee.WeiXin WeChat framework. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is an open source scripting language that is widely used in web development and server-side programming, especially in WeChat development. Today, more and more companies and developers are starting to use PHP for WeChat development because it has become a truly easy-to-learn and easy-to-use development language. In WeChat development, message encryption and decryption are a very important issue because they involve data security. For messages without encryption and decryption methods, hackers can easily obtain the data, posing a threat to users.

With the popularity of WeChat, more and more companies are beginning to use it as a marketing tool. The WeChat group messaging function is one of the important means for enterprises to conduct WeChat marketing. However, if you only rely on manual sending, it is an extremely time-consuming and laborious task for marketers. Therefore, it is particularly important to develop a WeChat mass messaging tool. This article will introduce how to use PHP to develop WeChat mass messaging tools. 1. Preparation work To develop WeChat mass messaging tools, we need to master the following technical points: Basic knowledge of PHP WeChat public platform development Development tools: Sub

In the development of WeChat public accounts, user tag management is a very important function, which allows developers to better understand and manage their users. This article will introduce how to use PHP to implement the WeChat user tag management function. 1. Obtain the openid of the WeChat user. Before using the WeChat user tag management function, we first need to obtain the user's openid. In the development of WeChat public accounts, it is a common practice to obtain openid through user authorization. After the user authorization is completed, we can obtain the user through the following code

As WeChat becomes an increasingly important communication tool in people's lives, its agile messaging function is quickly favored by a large number of enterprises and individuals. For enterprises, developing WeChat into a marketing platform has become a trend, and the importance of WeChat development has gradually become more prominent. Among them, the group sending function is even more widely used. So, as a PHP programmer, how to implement group message sending records? The following will give you a brief introduction. 1. Understand the development knowledge related to WeChat public accounts. Before understanding how to implement group message sending records, I

WeChat is currently one of the social platforms with the largest user base in the world. With the popularity of mobile Internet, more and more companies are beginning to realize the importance of WeChat marketing. When conducting WeChat marketing, customer service is a crucial part. In order to better manage the customer service chat window, we can use PHP language for WeChat development. 1. Introduction to PHP WeChat development PHP is an open source server-side scripting language that is widely used in the field of Web development. Combined with the development interface provided by WeChat public platform, we can use PHP language to conduct WeChat

In the development of WeChat public accounts, the voting function is often used. The voting function is a great way for users to quickly participate in interactions, and it is also an important tool for holding events and surveying opinions. This article will introduce you how to use PHP to implement WeChat voting function. Obtain the authorization of the WeChat official account. First, you need to obtain the authorization of the WeChat official account. On the WeChat public platform, you need to configure the API address of the WeChat public account, the official account, and the token corresponding to the public account. In the process of our development using PHP language, we need to use the PH officially provided by WeChat

With the popularity of mobile Internet, more and more people are using WeChat as a social software, and the WeChat open platform has also brought many opportunities to developers. In recent years, with the development of artificial intelligence technology, speech recognition technology has gradually become one of the popular technologies in mobile terminal development. In WeChat development, how to implement speech recognition has become a concern for many developers. This article will introduce how to use PHP to develop WeChat applications to implement speech recognition functions. 1. Principles of Speech Recognition Before introducing how to implement speech recognition, let us first understand the language

With the development of the Internet and mobile smart devices, WeChat has become an indispensable part of the social and marketing fields. In this increasingly digital era, how to use PHP for WeChat development has become the focus of many developers. This article mainly introduces the relevant knowledge points on how to use PHP for WeChat development, as well as some of the tips and precautions. 1. Development environment preparation Before developing WeChat, you first need to prepare the corresponding development environment. Specifically, you need to install the PHP operating environment and the WeChat public platform
