Gaoming13\WechatPhpSdk\Api::create_qrcode PHP Method

create_qrcode() public method

生成带参数的二维码
public create_qrcode ( $scene_id, $expire_seconds ) : array(err,
return array(err,
    public function create_qrcode($scene_id, $expire_seconds = 0)
    {
        $url = self::API_DOMAIN . 'cgi-bin/qrcode/create?access_token=' . $this->get_access_token();
        $expire = $expire_seconds == 0 ? '' : '"expire_seconds": ' . $expire_seconds . ',';
        $action_name = $expire_seconds == 0 ? 'QR_LIMIT_SCENE' : 'QR_SCENE';
        $xml = sprintf('{%s"action_name": "%s", "action_info": {"scene": {"scene_id": %s}}}', $expire, $action_name, $scene_id);
        $res = HttpCurl::post($url, $xml, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }
        // 判断是否调用成功
        if (isset($res->ticket)) {
            return array(null, $res);
        } else {
            return array($res, null);
        }
    }