Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of slow domain name resolution of WeChat Pay api.mch.weixin.qq.com in php version

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to solve the problem of slow domain name resolution of WeChat Pay api.mch.weixin.qq.com in php version. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

WeChat Pay api.mch.weixin.qq.com domain name resolution is slow, resulting in very slow payment, so how to solve WeChat Pay's slow problem, let's analyze it together.

When a friend implemented WeChat Pay logic on Ali CVM, he found that the resolution of api.mch.weixin.qq.com was too slow.

As a result, there is a situation of manual modification / etc/hosts. Of course, if WeChat Pay changes to another computer room one day, he will definitely hang up.

Our computer room also has the same question, specially record it.

The code uses curl to request Wechat and often times out, so try using wget:

[root@01 tmp] # wget api.mch.weixin.qq.com--2016-06-18 14 wget api.mch.weixin.qq.com--2016 51 wget api.mch.weixin.qq.com--2016 03muri-http://api.mch.weixin.qq.com/Resolving api.mch.weixin.qq.com...

Domain name resolution hasn't come out for a long time.

The test confirmed that it was an ipv6 problem.

Add-4 to wget to force the use of ipv4, and if it's fast, it's basically ipv6's fault.

[root@01 tmp] # wget-4 api.mch.weixin.qq.com--2016-06-18 17 wget 03purl 52muri-http://api.mch.weixin.qq.com/Resolving api.mch.weixin.qq.com... 123.151.71.149, 123.151.79.109Connecting to api.mch.weixin.qq.com | 123.151.71.149 |: 80. Connected.

Code analysis

Write a special code to test the parsing of ipv6, using the system function getaddrinfo:

# include # include using namespace std;int main () {struct addrinfo hints,*answer,*curr,*p; int error; memset (& hints, 0, sizeof hints); hints.ai_family = AF_INET6;//AF_UNSPEC; / / use AF_INET6 to force IPv6 hints.ai_socktype = SOCK_STREAM;//SOCK_DGRAM / SOCK_STREAM if ((error = getaddrinfo ("api.mch.weixin.qq.com", NULL, & hints, & answer)! = 0) {fprintf (stderr, "getaddrinfo:% s\ n", gai_strerror (error)); return 1;} else cout ai_addr))-> sin_addr), ipstr, 16); printf ("% s\ n", ipstr);} freeaddrinfo (answer); return 0;}

Include header file

Netdb.h

Function prototype:

Int getaddrinfo (const char hostname, const char service, const struct addrinfo * hints, struct addrinfo * * result)

Parameter description:

Hints: can be a null pointer or a pointer to an addrinfo structure in which the caller fills in a hint about the type of information expected to be returned. For example, if the specified service supports both TCP and UDP, the caller can set the ai_socktype member in the hints structure to SOCK_DGRAM so that only the information applicable to the Datagram socket is returned. Whether or not ipv6 is decided by ai_family.

Result: this function returns a pointer to the linked list of addrinfo structures through the result pointer argument.

Return value: 0 color-success, non-0 color-error

Test results:

When ai_family is ipv6, only the resolution result of ipv6 will be found, and the domain name is not set either. When ai_family is AF_UNSPEC, it will first ipv6 and then ipv4, and the ipv6 resolution of the domain name api.mch.weixin.qq.com is surprisingly slow (qq.com is not slow, see later).

Solution:

If curl,c can be forced to specify ipv4, use curl_easy_setopt (curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4)

Other languages also refer to this method.

Deep cause analysis

Nslookup-query=AAAA api.mch.weixin.qq.com-debug cannot be parsed (the specified AAAA is ipv6), and then you will find a SOA declaration that there is an ipv6 CNAME with his superior weixin.qq.com, to minorshort.weixin.qq.com, and the domain name is not resolved by ipv6.

Visual ipv6 is circled in this place of SOA and CNAME when looking for resolution. Do the students of Wechat consider making everyone feel better and remove the ipv6 settings for these domain names?

Dig @ ns-tel1.qq.com weixin.qq.com AAAAweixin.qq.com. 43200 IN SOA ns-tel1.qq.com. Webmaster.qq.com. 1293502040 300600 86400 86400 is how to solve the problem of slow domain name resolution of WeChat Pay api.mch.weixin.qq.com in php. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report