支付宝小程序二维码内容生成

api:

https://docs.alipay.com/miniapp/introduce/qrcode

支付宝生成小程序二维码内容:

public String createAliQRCode(String url_param,String query_param,String describe,Environment env) throws AlipayApiException {
        AlipayClient alipayClient = new DefaultAlipayClient(
                env.getProperty("alipay.url"),
                env.getProperty("alipay.app_id"),
                env.getProperty("alipay.private_key"),
                "json",
                "utf-8",
                env.getProperty("alipay.alipay_public_key"),
                "RSA2");

        //设置请求参数
        Map alipayMap=new HashMap<>();
        alipayMap.put("url_param",url_param);//小程序中能访问到的页面路径
        alipayMap.put("query_param",query_param);//小程序的启动参数,打开小程序的query,在小程序onLaunch的方法中获取
        alipayMap.put("describe",describe);//对应的二维码描述
        //参数转化位json格式
        String json = new Gson().toJson(alipayMap);
        AlipayOpenAppQrcodeCreateRequest request = new AlipayOpenAppQrcodeCreateRequest();
        request.setBizContent(json);

        AlipayOpenAppQrcodeCreateResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
            return response.getQrCodeUrl();
        } else {
            System.out.println("调用失败");
            return "";
        }

    }

 

你可能感兴趣的:(java)