Home  >  Article  >  WeChat Applet  >  Force.com WeChat development series custom menu advanced and speech recognition

Force.com WeChat development series custom menu advanced and speech recognition

高洛峰
高洛峰Original
2017-02-25 16:46:151697browse

In the above article we introduced how to add a custom menu to the WeChat account through the Force.com platform. In this article we will further introduce the relevant knowledge of how to query the menu and delete the menu. Finally, we will introduce how the WeChat platform performs speech recognition. related technologies.

Query menu

Similar to the creation menu, the query menu has its own interface, in which ACESS_TOKEN needs to be obtained through the interface introduced above, and usually expires after 2 hours:

https://api.weixin.qq.com/cgi-bin/menu/get?access_token=[ACCESS_TOKEN]

To do this, first obtain the Access_Token as introduced above, and obtain the real request URL similar to the following:

https://api.weixin.qq.com/cgi-bin/menu/get?access_token=RKkFQMHmXuTWPoCzEB9lYY_bksaBzxqKqE5FG0nW_74YXREheG3IyIoz9YvebQLI_6Vq9mD_rVD1iSXC1JzaBg

Run this in browsers such as IE link and save the corresponding file Open it and you will see the current menu structure of the WeChat account (viewing through different browsers may cause garbled display problems, etc. This is caused by the default encoding display problem of the browser. Download it and view it through Notepad to see the corresponding real Text):

Force.com WeChat development series custom menu advanced and speech recognition

Delete menu

After using the interface to create a custom menu, developers can also use the interface to delete the currently used custom menu and delete the menu. The interface is as follows:

https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=[ACCESS_TOKEN]

When correct, the returned JSON data packet is as follows:

{“errcode”:0, “errmsg”:”ok”}

Speech recognition

WeChat public account can be obtained after passing WeChat authentication Speech recognition interface. After the speech recognition function is turned on, every time the user sends a voice to the WeChat account, WeChat will add a Recognition field to the pushed voice message XML packet. This field is the text content recognized by Evian. The following is an example of a voice XML data packet after speech recognition is turned on:

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1357290913</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<MediaId><![CDATA[media_id]]></MediaId>
<Format><![CDATA[Format]]></Format>
<Recognition><![CDATA[腾讯微信团队]]></Recognition>
<MsgId>1234567890123456</MsgId>
</xml>

For the description of each parameter, see the figure below:

Force.com WeChat development series custom menu advanced and speech recognition

Foreword Force.com WeChat development Series (3) Applying for a test account and replying to a graphic message already includes how to parse the value of the node, and this attribute is also included in the corresponding IncomingMsg class. What needs to be done next is to determine the message type in the doPost method. Partially add the processing code for voice type messages:

else if(msgType.equals(&#39;voice&#39;)){
     rtnMsg = handleVoice(inMsg);
 }

Here we call the handleVoice method after identifying the message type as voice type and pass the IncomingMsg object to process the sound. The handleVoice method code is as follows:

 private static String handleVoice(IncomingMsg msg){
         String result = &#39;您说了: &#39; + msg.recognition;
         return composeTextReply(msg, result);
 }

Code Read the content of the Recognition node in the XML question passed after recognition by the Tencent platform and return it to the user. After saving the code, try to send the voice to the WeChat test account. The operation effect is as follows:

Force.com WeChat development series custom menu advanced and speech recognition

For more articles related to Force.com WeChat development series custom menu advancement and speech recognition, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn