Home >Backend Development >PHP Tutorial >(Static link QR code scanned with WeChat) Several bug corrections in the demo file officially provided by WeChat native payment model, nativedemo_PHP tutorial
native payment mode 1 Demo (static link QR code scanned with WeChat) bug fix, a total of 4 bugs
1. The code in the native_call_qrcode.php file cannot survive the native payment short address
2. A certain code in WxPayPubHelper.php cannot obtain the constant CURL_TIMEOUT defined by the WxPayConf_pub class
3. WxPayPubHelper.php curl The cURL session is in progress and resources are released abnormally
4. The WeChat payment long address conversion address function is incorrect
1. Correct the problem that the payment QR code is not generated from the WeChat short message address. The page address native_call_qrcode.php
line 39: because the official $codeUrl is empty .
Line 59:
<span>var</span> url = "<?php echo <span>$product_url</span>;?>";
Get the long address
Change it to the short address:
<span>var</span> url = "<?php echo <span>$codeUrl</span>;?>";
The amount of character information in a long address often causes scan failure.
2. A certain code in WxPayPubHelper.php cannot obtain the constant CURL_TIMEOUT defined by the WxPayConf_pub class
WxPayPubHelper/WxPayPubHelper.php
Line 155
curl_setopt(<span>$ch</span>, CURLOP_TIMEOUT, <span>$second</span>);
CURLOP_TIMEOUT cannot be obtained here
should be changed to
curl_setopt(<span>$ch</span>, WxPayConf_pub::CURL_TIMEOUT, <span>$second</span>);
3. The cURL session in WxPayPubHelper.php curl and the resource is released abnormally
Line 176 return $data; is superfluous, and an error will be reported here because line 171:
curl_close(<span>$ch</span>);
Stream has been closed
4. The WeChat payment long address conversion address function is incorrect
Line 600 getShortUrl() cannot obtain the short address,
<span>function</span><span> getShortUrl() { </span><span>$this</span>-><span>postXml(); </span><span>$prepay_id</span> = <span>$this</span>->result["short_url"<span>]; </span><span>return</span> <span>$prepay_id</span><span>; }</span>
Modify as follows
<span>function</span><span> getShortUrl() { </span><span>$this</span>-><span>postXml(); </span><span>$postObj</span> = <span>simplexml_load_string</span>(<span>$this</span>->response, 'SimpleXMLElement',<span> LIBXML_NOCDATA); </span><span>$prepay_id</span> = <span>$postObj</span>-><span>short_url; </span><span>return</span> <span>$prepay_id</span><span>; }</span>
WeChat development communication QQ:187395037 Tel: 15889726201