小程序二维码

详细小程序二维码参考指引

alipay.open.app.qrcode.create

生成小程序推广二维码

请求地址

环境HTTPS请求地址
正式环境https://openapi.alipay.com/gateway.do

公共请求参数

名称类型必填描述
app_idString支付宝分配给开发者的应用ID
methodString接口名称
formatString仅支持JSON
charsetString请求使用的编码格式,如utf-8,gbk,gb2312等
sign_typeString商户生成签名字符串所使用的签名算法类型,目 前支持RSA2和RSA,推荐使用RSA2
signString商户请求参数的签名串,详见签名
timestampString发送请求的时间,格式"yyyy-MM-dd HH:mm:ss"
versionString调用的接口版本,固定为:1.0
app_auth_tokenString详见应用授权概述
biz_contentString请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档

请求参数

名称类型必填示例描述
url_paramStringpage/component/component-pages/view/view小程序中能访问到的页面路径
query_paramStringx=1小程序的启动参数,打开小程序的query,在小程序onLaunch的方法中获取
describeString二维码描述对应的二维码描述

公共响应参数

名称类型必填描述
codeString网关返回码
msgString网关返回码描述
sub_codeString网关明细返回码
sub_msgString网关明细返回码描述
signString签名

响应参数

名称类型必填描述
qr_code_urlString二维码图片链接地址

代码示例

java版本

  1. AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
  2. AlipayOpenAppQrcodeCreateRequest request = new AlipayOpenAppQrcodeCreateRequest();
  3. request.setBizContent("{" +
  4. "\"url_param\":\"page/component/component-pages/view/view\"," +
  5. "\"query_param\":\"x=1\"," +
  6. "\"describe\":\"二维码描述\"" +
  7. " }");
  8. AlipayOpenAppQrcodeCreateResponse response = alipayClient.execute(request);
  9. if(response.isSuccess()){
  10. System.out.println("调用成功");
  11. } else {
  12. System.out.println("调用失败");
  13. }

php版本

  1. $aop = new AopClient ();
  2. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  3. $aop->appId = 'your app_id';
  4. $aop->rsaPrivateKey = '请填写开发者私钥去头去尾去回车,一行字符串';
  5. $aop->alipayrsaPublicKey='请填写支付宝公钥,一行字符串';
  6. $aop->apiVersion = '1.0';
  7. $aop->signType = 'RSA2';
  8. $aop->postCharset='GBK';
  9. $aop->format='json';
  10. $request = new AlipayOpenAppQrcodeCreateRequest ();
  11. $request->setBizContent("{" .
  12. "\"url_param\":\"page/component/component-pages/view/view\"," .
  13. "\"query_param\":\"x=1\"," .
  14. "\"describe\":\"二维码描述\"" .
  15. " }");
  16. $result = $aop->execute ( $request);
  17. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  18. $resultCode = $result->$responseNode->code;
  19. if(!empty($resultCode)&&$resultCode == 10000){
  20. echo "成功";
  21. } else {
  22. echo "失败";
  23. }

.Net版本

  1. IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", "app_id", "merchant_private_key", "json", "1.0", "RSA2", "alipay_public_key", "GBK", false);
  2. AlipayOpenAppQrcodeCreateRequest request= new AlipayOpenAppQrcodeCreateRequest() ;
  3. request.BizContent="{" +
  4. "\"url_param\":\"page/component/component-pages/view/view\"," +
  5. "\"query_param\":\"x=1\"," +
  6. "\"describe\":\"二维码描述\"" +
  7. " }";
  8. AlipayOpenAppQrcodeCreateResponse response=client.Execute(request);
  9. Console.WriteLine(response.Body);

HTTP版本

  1. https://openapi.alipay.com/gateway.do?timestamp=2013-01-01 08:08:08&method=alipay.open.app.qrcode.create&app_id=2893&sign_type=RSA2&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&biz_content=
  2. {"url_param":"/index.html?name=ali&loc=hz", "query_param":"name=1&age=2", "describe":"二维码描述"}
  3. //为确保安全通信,需自行验证响应示例中的sign值是否为蚂蚁金服所提供。

响应示例

json示例

  1. {
  2. "alipay_open_app_qrcode_create_response": {
  3. "code": "10000",
  4. "msg": "Success",
  5. "qr_code_url": "http://mmtcdp.stable.alipay.net/wsdk/img?fileid=A*lSbPT5i9C1wAAAAAAAAAAABjAQAAAA&t=9005d7f574f30246b89c20c17302115f&bz=mmtcafts&"
  6. },
  7. "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
  8. }

异常示例

json示例

  1. {
  2. "alipay_open_app_qrcode_create_response": {
  3. "code": "20000",
  4. "msg": "Service Currently Unavailable",
  5. "sub_code": "isp.unknow-error",
  6. "sub_msg": "系统繁忙"
  7. },
  8. "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
  9. }

业务错误码

公共错误码

错误码错误描述解决方案
INVALID_PARAMETER参数有误检查请求参数是否传入
APPQRCODE_NOT_TINYAPP非小程序应用类型检查app应用类型,本接口只支持小程序的应用
SYSTEM_ERROR系统繁忙稍后重试
APP_QUERY_ERROR应用查询错误确认应用是否存在,如果应用存在,则稍后重试

原文: https://docs.alipay.com/mini/api/openapi-qrcode