Home WeChat Applet WeChat Development Detailed graphic and text explanation of WeChat server IP interface examples developed by WeChat public platform (with code)

Detailed graphic and text explanation of WeChat server IP interface examples developed by WeChat public platform (with code)

Mar 18, 2017 am 09:28 AM

This article mainly introduces detailed graphic and text examples of WeChat server IP interface development on WeChat public platform (with code), which has a good reference value. Let’s take a look with the editor below

After learning how to obtain and apply access_token, formally use access_token to call the interfaces of other WeChat public platforms to deepen our understanding and usage.

1. Example of obtaining the IP address of the WeChat server

(1) Interface introduction

If Due to security and other considerations, public accounts need to know the IP address list of the WeChat server in order to implement relevant restrictions. You can obtain the WeChat server IP address list or IP network segment information through this interface.

(2) Instance call

Interface description

http request method: GET

Interface call Address:

api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN

Request parameter description, as shown in the table:


Parameters

Is it required

Description

access_token

is the access_token# of the

official account

##Return instructions:

Under normal circumstances, WeChat will return the

JSON data packet to the official account, as shown in the figure :

Detailed graphic and text explanation of WeChat server IP interface examples developed by WeChat public platform (with code)

Return information parameter description, as shown in the table:


Parameters

Description

ip_list

WeChat server IP address list

Code:

<?php
/*
 *获取微信服务器IP地址
*/
require(&#39;wei_function.php&#39;);
$appid="wx78478e595939c538";
$secret="5540e8ccab4f71dfad752f73cfb85780";
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
$output=getdata($url);
$token=(array)json_decode($output);
//获取到access_token参数
$token=$token[&#39;access_token&#39;];
//获取微信服务器IP接口地址
$ipurl="https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=".$token."";
$iparr=(array)json_decode(getdata($ipurl));
foreach ($iparr[&#39;ip_list&#39;] as $key => $value) {
  echo $value."<br>";//用循环的方式打印IP集合
}
?>
Copy after login

Code analysis:

require('wei_function. php'); Contains wei_function.php

Use the getdata() function. After obtaining the access_token, continue to replace the access_token value of the $ipurl value;

$iparr=(array)json_decode(getdata( $ipurl)); Obtain the data of $ipurl through the getdata() function, and then process it through the json_decode function to obtain $iparr. At this time, the variable value is a

two-dimensional array, as shown in the figure ;

Detailed graphic and text explanation of WeChat server IP interface examples developed by WeChat public platform (with code)

What we need is [ip_list] in the array, so we take out the array set of [ip_list] separately, and loop out each WeChat server IP through foreach,

Code:

foreach ($iparr[&#39;ip_list&#39;] as $key => $value)
{
echo $value."<br>";//用循环的方式打印IP集合
}
Copy after login


The result of running the program calling interface is as shown in the figure.

Detailed graphic and text explanation of WeChat server IP interface examples developed by WeChat public platform (with code)

The above is the detailed content of Detailed graphic and text explanation of WeChat server IP interface examples developed by WeChat public platform (with code). 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)