# 获取小程序码

该接口方法需要安装 小程序码和小程序链接,如未安装需要前往安装才可以使用

# 接口英文名

wx_qrcode_get_qrcode

# 功能描述

该接口用于获取小程序码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制。

# 调用方式

接口已做处理,返回小程序码的url,不会返回buffer类型的数据,便于直接使用。

wx.cloud.callFunction({
  name: 'cloudbase_module',
  data: {
    name: 'wx_qrcode_get_qrcode',
    data: {
      path: 'pages/index/index', // 扫码进入的小程序页面路径,最大长度 1024 个字符,不能为空,scancode_time为系统保留参数,不允许配置;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar",即可在 wx.getLaunchOptionsSync 接口中的 query 参数获取到 {foo:"bar"}。
      width: 430, //二维码的宽度,单位 px。默认值为430,最小 280px,最大 1280px
      auto_color: false, //默认值false;自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
      line_color: { r: 0, g: 0, b: 0 }, //默认值{"r":0,"g":0,"b":0} ;auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示
      is_hyaline: false, //默认值false;是否需要透明底色,为 true 时,生成透明底色的小程序码
      env_version: 'trial', //要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
    },
  },
  success: (res) => {
    console.log('综合结果', res.result.result);
    console.log('错误码', res.result.errcode);
    console.log('错误信息', res.result.errmsg);
  },
});

# 更多说明和错误码

参考微信小程序获取小程序码

# 入参:

参数 类型 必填 描述
path string 扫码进入的小程序页面路径,最大长度 1024 个字符,不能为空,scancode_time为系统保留参数,不允许配置;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 '?foo=bar',即可在 wx.getLaunchOptionsSync 接口中的 query 参数获取到 {foo:'bar'}
width number 二维码的宽度,单位 px。默认值为430,最小 280px,最大 1280px
auto_color boolean 默认值false;自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
line_color object
line_color.r string auto_color 为 false 时生效
line_color.g string auto_color 为 false 时生效
line_color.b string auto_color 为 false 时生效
is_hyaline boolean 默认值false;是否需要透明底色,为 true 时,生成透明底色的小程序码
env_version string

# 出参:

参数 类型 描述
result object
result.buffer string 图片url
result.errcode number 错误码
result.errmsg string 错误信息
errmsg string 微信开放接口错误信息
requestID object 微信开放接口请求 ID