Table of Contents
4.自定义菜单中事件的推送:" >4.自定义菜单中事件的推送:
5.微信关注回复:" >5.微信关注回复:
6.数据库的使用(图灵机器人的使用):
7.百度地图的使用:" >7.百度地图的使用:
Home Backend Development PHP Tutorial Complete Tutorial Three on WeChat Public Account Development

Complete Tutorial Three on WeChat Public Account Development

Apr 17, 2018 am 09:57 AM
whole develop Tutorial

This article introduces the third complete tutorial on WeChat public account development. It has certain reference value. Now I share it with everyone. Friends in need can refer to it

because of work needs , in the past two years, there have been many projects on WeChat public accounts and mini programs. That’s why I plan to write a comprehensive production tutorial. Of course, the best tutorial is the documentation of the WeChat work platform. I'm just going to talk about the production process in my work here. I host the source code of all related articles on my own github. Welcome to follow: Address Click to open the link. Let's start our tutorial.

For WeChat development, the most important thing is actually to read the WeChat developer documentation, write and replace variables carefully, and debug errors carefully, and slowly achieve your own goals. Require. The Baidu Map and Turing Robot mentioned in the second article, we will talk about it in this section:

Let me show you the effect first: Turing Robot


Using Baidu Map:


##In this section, we will start to explain the use of custom menus: After the description is completed, we will start to talk about Baidu and Turing Robot

1. Custom menu

WeChat’s documentation:


Type of button for custom menu:


Interface Description:


The code is as follows: (can be tested locally)


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

public function creatMenu()

{

//组装请求的url地址

$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$this->accessToken;

$data = array(

// button下的每一个元素

"button"=>array(

//第一个一级菜单

array('type'=>'click',"name"=>"个人简介","key"=>"info"),

array(

"name"=>"语言排行",

"sub_button"=>array(

array("name"=>'商品列表',"type"=>"view",

'url'=>"http://xiaoziheng.club/home/demo/demo4"),

array('name'=>'c/c++','type'=>'pic_sysphoto','key'=>'sysptoto'),

array('name'=>'java','type'=>'pic_weixin','key'=>'pic_weixin')

)

),

array('type'=>'click','name'=>'xxxx','key'=>'content')

)

);

//    将数据转换为json格式

$data = json_encode($data,JSON_UNESCAPED_UNICODE);

$result = http_curl($url,$data,'post');

dump($result);

}

Copy after login

The results are as follows:



##2.Since Define menu query:


Code:

##

1

2

3

4

5

6

7

//获取自定义菜单

public function getMenu()

{

$url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".$this->accessToken;

$res =http_curl($url);

var_dump($res);

}

Copy after login


Result: Array display (a little abnormal here, but the result is no problem)


3. Custom menu deletion:


# #Code:

##

1

2

3

4

5

6

7

// 删除自定义菜单

public function delMenu()

{

$url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token='.$this->accessToken;

$res =http_curl($url);

dump($res);

}

Copy after login

Result:



4.自定义菜单中事件的推送:

文档:


代码:


结果如下:


5.微信关注回复:

微信文档

代码如下:


结果如下:


6.数据库的使用(图灵机器人的使用):

我们可以在数据库建立关键字的数据表,让关注者回复的内容可以被我们控制,


如果没有内容找到,那么我们就使用图灵机器人来帮助我们:

首先进入官网:


创建机器人:我已经申请过一个


获得接入的key:


查看文档的使用:


代码:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

// 根据keyword表中的字段进行相等匹配

$info = db('Keyword')->where(array('keyword'=>$keyword))->find();

if(!$info){

//针对没有匹配的关键词使用机器人回复

$url ="http://www.tuling123.com/openapi/api?key=96308475006241449b53013d66f8e387&info="

                                           .$keyword;

$result = file_get_contents($url);

$result = json_decode($result,true);

if($result['code'] == 100000){

// 回复文本消息

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, 'text',

$result['text']);

}elseif ($result['code'] == 200000) {

$str = &#39;<a href="&#39;.$result[&#39;url&#39;].&#39;">&#39;.$result[&#39;text&#39;].&#39;</a>&#39;;

// 机器人中区分为链接

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, &#39;text&#39;, $str);

}elseif ($result[&#39;code&#39;] ==302000) {

// 机器人中的新闻

$data = $result[&#39;list&#39;];

for($i=0;$i<8;$i++){

$Articles ="<item>

                                    <Title><![CDATA[{$data[$i][&#39;article&#39;]}]]></Title>

                                    <Description><![CDATA[{$data[$i][&#39;article&#39;]}]]></Description>

                                    <PicUrl><![CDATA[{$data[$i][&#39;icon&#39;]}]]></PicUrl>

                                    <Url><![CDATA[{$data[$i][&#39;detailurl&#39;]}]]></Url>

                                </item>";

}

$count = 1;

$resultStr = sprintf($newsTpc, $fromUsername, $toUsername, $time,

&#39;news&#39;,$count,$Articles);

}else{

// 回复文本消息

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, &#39;text&#39;,

                                &#39;抱歉没有理解,再说一遍问题&#39;);

}

echo $resultStr;

// file_put_contents(&#39;2&#39;,33333);

exit;

}

Copy after login

效果就是我上述的截图一样。

7.百度地图的使用:

基于地理位置的定位服务,根据经度纬度定位用户的具体地址

LBSLocation Based Service):基于地理位置的服务

$longitude 经度

$latitude 纬度

接口的获取:



代码如下:


结果如文章开始的时候的截图。

The next section talks about the WeChat development of web page authorization...

Related recommendations:

Complete Tutorial on WeChat Public Account Development Two

Complete Tutorial on WeChat Public Account Development One

The above is the detailed content of Complete Tutorial Three on WeChat Public Account Development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Tutorial on how to use Dewu Tutorial on how to use Dewu Mar 21, 2024 pm 01:40 PM

Dewu APP is currently a very popular brand shopping software, but most users do not know how to use the functions in Dewu APP. The most detailed usage tutorial guide is compiled below. Next is the Dewuduo that the editor brings to users. A summary of function usage tutorials. Interested users can come and take a look! Tutorial on how to use Dewu [2024-03-20] How to use Dewu installment purchase [2024-03-20] How to obtain Dewu coupons [2024-03-20] How to find Dewu manual customer service [2024-03-20] How to check the pickup code of Dewu [2024-03-20] Where to find Dewu purchase [2024-03-20] How to open Dewu VIP [2024-03-20] How to apply for return or exchange of Dewu

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

What software is photoshopcs5? -photoshopcs5 usage tutorial What software is photoshopcs5? -photoshopcs5 usage tutorial Mar 19, 2024 am 09:04 AM

PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

See all articles