1. Interface document address

Obtain small program code, suitable for the business scenario where the number of required codes is very large. The small program code generated through this interface is valid forever and the number is temporarily unlimited.

  • Address navigation:Official wechat document -> Small program -> The service side -> Small program code -> getUnlimited Please go to document address >>>

Two, interface call

  • Please refer to the official documentation for details of the call >>>

Third, return value

1, description,

  • If the call is successful, it returns image == binary content == directly, if the request fails, it returns data in ==JSON format ==.

2. Return normally

  • Image Buffer returned

3. Exception return

  • Data format:json
  • Json content: ErrCode (number) – Error code; Errmsg (string) – Error message
  • Valid value of errCode: 45009- The call minute frequency is limited (currently 5000 times/minute, it will be adjusted). If a large number of small program codes are required, it is recommended to pre-generate them. 41030- The passed Page page does not exist or the applets have not been published

Fourth, pay attention to

  • POSTThe parameter needs to be converted toJSONA character string. Not supportedformForm submission.
  • Interface can only generate the QR code of published applets
  • Limited call minute frequency (5000 beats per minute), if you need a lot of small program code, it is recommended to pre-generate
  • sceneParameters:Contains a maximum of 32 visible characters, == Supports only digits, uppercase and lowercase letters, and some special characters:! # $& ‘() *, + / :; =? @-._~==, other characters must be encoded as valid characters. (Chinese characters cannot be used because == does not support %==urlencodePlease use other encoding method)
  • pageParameter: The value must bePage where the published applets existOtherwise an error is reported, for example pages/index/indexBefore the root pathDo not add /, cannot carry parameters (please put parameters in the scene field), == If this field is not filled in, the default page == will be skipped

PHP calls

  • code
public function test() {
    $result = self::getQrCode();
    var_export($result);
    die(a); }// Get the qr code
public function getQrCode() {
    $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN';
    $data = [
        'scene'= >'uid=1&orderId=2'.// Contains a maximum of 32 visible characters, including digits, uppercase and lowercase characters, and some special characters:! # $& '() *, + / :; =? @-._~, other characters should be encoded as legitimate characters (Chinese characters cannot be processed by Urlencode because % is not supported, please use other encoding methods).
        'page'= >' '.// It must be a page that has already been published, such as pages/index/index. Do not add/before the root path, and do not carry parameters (please put parameters in the scene field). If you do not fill in this field, the default page will be skipped
        'width'= >200.// Width of qr code, unit: px, minimum: 280px, maximum: 1280px
    ];
    $result = self::curlPostJson($url.$data);
    return $result;
}

    / / json post request
public function curlPostJson($url.$data.$header = []) {
    $data = json_encode($data);
    $ch = curl_init();
    if (!empty($data)) {
        curl_setopt($ch, CURLOPT_POST,true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    $header[] ='Content-Type: application/json; charset=utf-8';
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // If true, the crawl redirected page is tracked; otherwise, the redirected page is not tracked
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Set the timeout period to 30s
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // Ignore SSL detection
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //1 or TRUE returns information retrieved by curl_exec() as a string rather than output it directly. -
    curl_setopt($ch, CURLINFO_HEADER_OUT, true); // trace the request string for the handle when TRUE, available as of PHP 5.1.3. And this is key, is to allow you to see the request header
    curl_setopt($ch, CURLOPT_URL, $url);
    $output = curl_exec($ch);
    if (!$output) {
// echo "request $url fail:", (array)curl_error($ch); // Log
    }
    curl_close($ch);
// echo "request $url success:" . json_encode(array($url, $header, $output), true); // Log
    return $output;
}
Copy the code
  • The output
'{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest rid: 60a3271a-770b3ab0-448314f5"}'
Copy the code