This article mainly introduces server IP interface instances in public platform development, which has good reference value. Next let's take a look at it with a small Editor. This article mainly introduces the public platform development server IP interface instance (with code), which has good reference value. Let's take a look at it with the small editor.
After learning how to obtain and apply access_token, you can use access_token to call interfaces of other public platforms to deepen your understanding and usage.
1. obtain the server IP address instance
(1) interface introduction
If the public account is based on security and other considerations, you need to know the server IP address list for restrictions, you can obtain the server IP address list or IP address 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
The request parameters are described in the following table:
Parameters |
Required? |
Description |
Access_token |
Yes |
Access_token of the public account |
Return description:
Normally, a JSON data packet is returned to the public account ,:
Parameters |
Description |
Ip_list |
Server IP address list |
Code:
$ Value) {echo $ value ."
"; // Print the IP set in a circular manner}?>
Code parsing:
Require ('Wei _ function. php'); contains wei_function.php
Use the getdata () function to replace the value of $ ipurl with the value of access_token after obtaining the access_token;
$ Iparr = (array) json_decode (getdata ($ ipurl); get $ ipurl data through the getdata () function, and then get $ iparr after processing through the json_decode function, the variable value is a two-dimensional array ,;
What we need is [ip_list] in the array. Therefore, we extract the array set of [ip_list] separately and use foreach to loop through each server IP address,
Code:
Foreach ($ iparr ['IP _ list'] as $ key => $ value) {echo $ value ."
"; // Print the IP set in a loop}
Run the program to call the interface result ,.
The above is a detailed description of the public platform development server IP interface instance (with code) details, please pay attention to other articles related to php Chinese network!