WeChat public platform development-WeChat Server IP interface instance (including source code), ip containing source code

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.