Public platform development-Server IP interface instance (including source code), ip including source code
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:
Https://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 ,:
The following table describes the response parameters:
Parameters |
Description |
Ip_list |
Server IP address list |
Code:
<? Php/** get Server IP Address */require ('wei _ function. php'); $ appid = "wx78478e595939c538"; $ secret = "Courier"; $ 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 ); // get the access_token parameter $ token = $ token ['Access _ token']; // get the Server IP address $ ipurl = "https://api.weixin.qq.com/cgi-bin/getcallbackip? Access_token = ". $ token. ""; $ iparr = (array) json_decode (getdata ($ ipurl); foreach ($ iparr ['IP _ list'] as $ key => $ value) {echo $ value. "<br>"; // print the IP Set in a loop.}?>
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. "<br>"; // print the ip Set in a loop}
Run the program to call the interface result ,.
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!