Exemplo n.º 1
0
  /**
   * 获取永久二维码
   *
   * @param accessToken accessToken
   * @param sceneStr 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64,仅永久二维码支持此字段
   * @return 永久二维码链接,或抛WechatException
   */
  public String getPermQrcodeBySceneStr(String accessToken, String sceneStr) {
    checkNotNullAndEmpty(accessToken, "accessToken");
    checkNotNullAndEmpty(sceneStr, "sceneStr");

    String url = TICKET_GET + accessToken;
    Map<String, Object> params = buildQrcodeParams(null, sceneStr, QrcodeType.QR_LIMIT_STR_SCENE);

    Map<String, Object> resp = doPost(url, params);
    Qrcode qr = Jsons.DEFAULT.fromJson(Jsons.DEFAULT.toJson(resp), Qrcode.class);

    return showQrcode(qr.getTicket());
  }
Exemplo n.º 2
0
  /**
   * 获取临时二维码
   *
   * @param accessToken accessToken
   * @param sceneId 业务场景ID,32位非0整型
   * @param expire 该二维码有效时间,以秒为单位。 最大不超过604800(即7天)
   * @return 临时二维码链接,或抛WechatException
   */
  public String getTempQrcode(String accessToken, String sceneId, Integer expire) {
    checkNotNullAndEmpty(accessToken, "accessToken");
    checkNotNullAndEmpty(sceneId, "sceneId");
    checkArgument(expire != null && expire > 0, "expire must > 0");

    String url = TICKET_GET + accessToken;
    Map<String, Object> params = buildQrcodeParams(sceneId, null, QrcodeType.QR_SCENE);
    params.put("expire_seconds", expire);

    Map<String, Object> resp = doPost(url, params);
    Qrcode qr = Jsons.DEFAULT.fromJson(Jsons.DEFAULT.toJson(resp), Qrcode.class);
    return showQrcode(qr.getTicket());
  }