日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)百度小程序教程:二維碼長鏈
  • 二維碼長鏈
    • 解釋
    • 接口說明
    • 參數(shù)說明
      • query 參數(shù)
      • post 參數(shù)
      • 返回值說明
      • 正確情況下返回圖像的字節(jié)流,響應(yīng) header 中包含
      • 錯誤情況下返回
      • 返回信息
      • 錯誤碼
      • Bug&Tip
      • 請求示例

    二維碼長鏈

    解釋

    獲取小程序二維碼長鏈接,適用于需要的碼數(shù)量較多的業(yè)務(wù)場景。通過該接口生成的二維碼,永久有效,無數(shù)量限制。

    接口說明

     
     
     
    1. POST https://openapi.baidu.com/rest/2.0/smartapp/qrcode/getunlimited?access_token=ACCESS_TOKEN

    參數(shù)說明

    query 參數(shù)

    參數(shù)名 類型 是否必須 描述
    access_token String 接口調(diào)用憑證

    post 參數(shù)

    參數(shù)名 類型 是否必須 默認(rèn)值 示例 描述
    path String 主頁 pages/index/index 掃碼進(jìn)入的小程序頁面路徑,最大長度 4000 字節(jié),可以為空。
    width Int 430 500 二維碼的寬度(單位:px)。最小 280px,最大 1280px
    mf Int 1 1 是否包含二維碼內(nèi)嵌 logo 標(biāo)識,1001 為不包含,默認(rèn)包含

    返回值說明

     
     
     
    1. 如果調(diào)用成功,直接返回圖片二進(jìn)制內(nèi)容,如果請求失敗,會返回 JSON 格式的數(shù)據(jù)。

    正確情況下返回圖像的字節(jié)流,響應(yīng) header 中包含

     
     
     
    1. HTTP/1.1 200 OK
    2. Content-Type: image/png

    錯誤情況下返回

     
     
     
    1. HTTP/1.1 200 OK
    2. Content-Type : application/json

    返回信息

    名稱 類型 描述
    errno Int 錯誤碼
    errmsg String 錯誤信息
    request_id String 請求 ID ,標(biāo)識一次請求

    錯誤碼

    錯誤碼 描述
    110 access_token 錯誤
    400 輸入不合法(path 長度錯誤、width 長度錯誤)

    Bug&Tip

    • Tip:POST 只支持 form 表單提交。
    • Tip:正確返回 Content-Type:image/png

    請求示例

    • PHP
     
     
     
    1. class Common_Qrcode
    2. {
    3. const URL_SEND_REG = 'https://openapi.baidu.com/rest/2.0/smartapp/qrcode/getunlimited?';
    4. /**
    5. * @desc 獲取 access_token
    6. * https://smartprogram.baidu.com/docs/develop/serverapi/power_exp/
    7. * @param $appkey
    8. * @param $appSecret
    9. * @return bool|string
    10. */
    11. public static function getAccessToken($appkey, $appSecret) {
    12. $url = 'https://openapi.baidu.com/oauth/2.0/token?';
    13. $courierConf = Bd_Conf::getAppConf("classes/courier");
    14. $param = array(
    15. "grant_type" => 'client_credentials',
    16. "client_id" => $appkey,
    17. "client_secret" => $appSecret,
    18. "scope" => 'smartapp_snsapi_base',
    19. );
    20. $url .= http_build_query($param);
    21. $curl = curl_init((string)$url);
    22. curl_setopt($curl, CURLOPT_HEADER, false);
    23. // 信任任何證書
    24. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    25. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    26. $data = curl_exec($curl);
    27. curl_close($curl);
    28. $res = json_decode($data,1);
    29. if ($data === false || empty($res['access_token'])) {
    30. Bd_Log::warning("getToken fail! data[$data]");
    31. return false;
    32. }
    33. return $res['access_token'];
    34. }
    35. /**
    36. * @desc 獲取二維碼base64字節(jié)流
    37. * https://smartprogram.baidu.com/docs/develop/serverapi/get/
    38. * @param $path
    39. * @param $width
    40. * @return bool|string
    41. */
    42. public static function getQrCode($path, $width)
    43. {
    44. $accessToken = self::getAccessToken();
    45. if ($accessToken === false){
    46. return false;
    47. }
    48. $courierConf = Bd_Conf::getAppConf("classes/courier");
    49. $data = array(
    50. "path" => $path,
    51. "width" => $width,
    52. "expire" => $expire,
    53. );
    54. $res = self::curlPost($data,$accessToken);
    55. return $res;
    56. }
    57. /**
    58. * curl POST請求工具類
    59. * @param array $postDataArr 傳遞的數(shù)組參數(shù)
    60. * @return string | array
    61. */
    62. public static function curlPost($postDataArr,$accessToken)
    63. {
    64. $headerArr = array(
    65. "Content-type:application/x-www-form-urlencoded"
    66. );
    67. $url = self::URL_SEND_REG;
    68. $param = array(
    69. 'access_token'=>$accessToken,
    70. );
    71. $url .= http_build_query($param);
    72. $curl = curl_init((string)$url);
    73. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    74. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    75. curl_setopt($curl, CURLOPT_POST, 1);
    76. curl_setopt($curl, CURLOPT_POSTFIELDS, $postDataArr);
    77. curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArr);
    78. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    79. $output = curl_exec($curl);
    80. $info = curl_getinfo($curl);
    81. curl_close($curl);
    82. $res = '';
    83. if ($info["content_type"] == "image/png") {
    84. $res = base64_encode($output);
    85. }
    86. return $res;
    87. }
    88. }

    本文名稱:創(chuàng)新互聯(lián)百度小程序教程:二維碼長鏈
    網(wǎng)頁路徑:http://www.dlmjj.cn/article/djihdjh.html