danchaofan1412 3 лет назад
Родитель
Сommit
bdb1bfc73b

+ 55 - 0
framework-common/src/main/java/com/mrxu/framework/common/weixin/api/WxQrcodeApi.java

@@ -0,0 +1,55 @@
+package com.mrxu.framework.common.weixin.api;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.mrxu.framework.common.weixin.base.WxHttp;
+import com.mrxu.framework.common.weixin.bean.Qrcode;
+
+public class WxQrcodeApi {
+
+	private static String codeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=";
+
+	private static String qrcodeUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
+	
+	/**
+	 * 产生临时二维码
+	 * @param token
+	 * @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过604800(即7天)
+	 * @param value 32位非0整型
+	 * @return
+	 */
+	public static Qrcode getTempQrcode(String token,int expireSeconds, String value) {
+		JSONObject json = new JSONObject();
+		json.put("expire_seconds", expireSeconds);
+		json.put("action_name", "QR_STR_SCENE");
+		//json.put("action_info", "{\"scene\":{\"scene_id\":"+value+"}}");
+		
+		JSONObject actionInfo = new JSONObject();
+		JSONObject scene = new JSONObject();
+		scene.put("scene_str", value);
+		actionInfo.put("scene", scene);
+		json.put("action_info", actionInfo);
+		return WxHttp.post(Qrcode.class, qrcodeUrl+"?access_token="+token, json);
+	}
+	
+	/**
+	 * 产生永久二维码
+	 * @param token
+	 * @param value 32位非0整型
+	 * @return
+	 */
+	public static Qrcode getForeverQrcode(String token,String value) {
+		JSONObject json = new JSONObject();
+		json.put("action_name", "QR_LIMIT_STR_SCENE");
+		
+		JSONObject actionInfo = new JSONObject();
+		JSONObject scene = new JSONObject();
+		scene.put("scene_str", value);
+		actionInfo.put("scene", scene);
+		json.put("action_info", actionInfo);
+		
+		return WxHttp.post(Qrcode.class, qrcodeUrl+"?access_token="+token, json);
+	}
+
+
+}

+ 47 - 0
framework-common/src/main/java/com/mrxu/framework/common/weixin/bean/Qrcode.java

@@ -0,0 +1,47 @@
+package com.mrxu.framework.common.weixin.bean;
+
+import com.mrxu.framework.common.weixin.base.WxResult;
+
+
+public class Qrcode extends WxResult {
+
+	/**
+	 * 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。
+	 */
+	private String ticket;
+	
+	/**
+	 * 二维码的有效时间,以秒为单位。最大不超过1800
+	 */
+	private Integer expire_seconds;
+	
+	/**
+	 * 二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片
+	 */
+	private String url;
+
+	public String getTicket() {
+		return ticket;
+	}
+
+	public void setTicket(String ticket) {
+		this.ticket = ticket;
+	}
+
+	public Integer getExpire_seconds() {
+		return expire_seconds;
+	}
+
+	public void setExpire_seconds(Integer expire_seconds) {
+		this.expire_seconds = expire_seconds;
+	}
+
+	public String getUrl() {
+		return url;
+	}
+
+	public void setUrl(String url) {
+		this.url = url;
+	}
+	
+}