阅读(416) (0)

wx-tools 另外一些API调用示例,如二维码生产,短链接等

2018-05-12 09:54:24 更新

包括如下接口:
- createQrCode - 生成二维码
- downloadQrCode - 下载二维码
- getShortUrl - 获取短链接
- getCallbackIp - 获取微信服务器ip

3.8.1 createQrCode 生成二维码

    WxQrcode code = new WxQrcode();
    code.setAction_name("actionName");
    code.setAction_info(new WxQrActionInfo(new WxScene("scene_id/str")));
    code.setExpire_seconds(720);
    try {
        QrCodeResult result = iService.createQrCode(code);
        System.out.println(result.getUrl());
    } catch (WxErrorException e) {
        e.printStackTrace();
    }

3.8.2 downloadQrCode 下载二维码,需要用到createQrCode中的ticket

    try {
        File file = iService.downloadQrCode(new File("E://temp"), "ticket");
    } catch (WxErrorException e) {
        e.printStackTrace();
    }

3.8.3 getShortUrl 长链接变短链接

    try {
        String shortUrl = iService.getShortUrl("long_url");
    } catch (WxErrorException e) {
        e.printStackTrace();
    }

3.8.4 getCallbackIp获取微信服务器的ip段

    try {
        String [] ipList = iService.getCallbackIp();
    } catch (WxErrorException e) {
        e.printStackTrace();
    }