| @@ -1,5 +1,6 @@ | |||||
| package cn.binarywang.wx.miniapp.api; | package cn.binarywang.wx.miniapp.api; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import java.io.File; | import java.io.File; | ||||
| @@ -16,6 +17,9 @@ import java.io.File; | |||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
| */ | */ | ||||
| public interface WxMaQrcodeService { | public interface WxMaQrcodeService { | ||||
| String CREATE_QRCODE_URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode"; | |||||
| String GET_WXACODE_URL = "https://api.weixin.qq.com/wxa/getwxacode"; | |||||
| String GET_WXACODE_UNLIMIT_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit"; | |||||
| /** | /** | ||||
| * 接口C | * 接口C | ||||
| @@ -42,10 +46,8 @@ public interface WxMaQrcodeService { | |||||
| * @param width 默认430 二维码的宽度 | * @param width 默认430 二维码的宽度 | ||||
| * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | ||||
| * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | ||||
| * @return | |||||
| * @throws WxErrorException | |||||
| */ | */ | ||||
| File createWxCode(String path, int width, boolean autoColor, LineColor lineColor) throws WxErrorException; | |||||
| File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||||
| File createWxCode(String path, int width) throws WxErrorException; | File createWxCode(String path, int width) throws WxErrorException; | ||||
| @@ -65,49 +67,9 @@ public interface WxMaQrcodeService { | |||||
| * @param width 默认false 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | * @param width 默认false 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | ||||
| * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | * @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | ||||
| * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | * @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | ||||
| * @return | |||||
| * @throws WxErrorException | |||||
| */ | */ | ||||
| File createWxCodeLimit(String scene, String page, int width, boolean autoColor, LineColor lineColor) throws WxErrorException; | |||||
| File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||||
| File createWxCodeLimit(String scene, String page) throws WxErrorException; | File createWxCodeLimit(String scene, String page) throws WxErrorException; | ||||
| /** | |||||
| * lineColor 包装类 | |||||
| * 用于描述二维码(小程序码)颜色(RGB参数值),详情请查看文档 | |||||
| */ | |||||
| public static class LineColor { | |||||
| private String r = "0", g = "0", b = "0"; | |||||
| public LineColor(String r, String g, String b) { | |||||
| this.r = r; | |||||
| this.g = g; | |||||
| this.b = b; | |||||
| } | |||||
| public String getR() { | |||||
| return r; | |||||
| } | |||||
| public void setR(String r) { | |||||
| this.r = r; | |||||
| } | |||||
| public String getG() { | |||||
| return g; | |||||
| } | |||||
| public void setG(String g) { | |||||
| this.g = g; | |||||
| } | |||||
| public String getB() { | |||||
| return b; | |||||
| } | |||||
| public void setB(String b) { | |||||
| this.b = b; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl; | |||||
| import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaQrcode; | import cn.binarywang.wx.miniapp.bean.WxMaQrcode; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaWxcode; | import cn.binarywang.wx.miniapp.bean.WxMaWxcode; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaWxcodeLimit; | import cn.binarywang.wx.miniapp.bean.WxMaWxcodeLimit; | ||||
| @@ -22,9 +23,8 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||||
| @Override | @Override | ||||
| public File createQrcode(String path, int width) throws WxErrorException { | public File createQrcode(String path, int width) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode"; | |||||
| return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | ||||
| url, new WxMaQrcode(path, width)); | |||||
| CREATE_QRCODE_URL, new WxMaQrcode(path, width)); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -33,15 +33,14 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public File createWxCode(String path, int width, boolean autoColor, LineColor lineColor) throws WxErrorException { | |||||
| String url = "https://api.weixin.qq.com/wxa/getwxacode"; | |||||
| public File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { | |||||
| WxMaWxcode wxMaWxcode = new WxMaWxcode(); | WxMaWxcode wxMaWxcode = new WxMaWxcode(); | ||||
| wxMaWxcode.setPath(path); | wxMaWxcode.setPath(path); | ||||
| wxMaWxcode.setWidth(width); | wxMaWxcode.setWidth(width); | ||||
| wxMaWxcode.setAutoColor(autoColor); | wxMaWxcode.setAutoColor(autoColor); | ||||
| wxMaWxcode.setLineColor(lineColor); | wxMaWxcode.setLineColor(lineColor); | ||||
| return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | ||||
| url, wxMaWxcode); | |||||
| GET_WXACODE_URL, wxMaWxcode); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -55,8 +54,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public File createWxCodeLimit(String scene, String page, int width, boolean autoColor, LineColor lineColor) throws WxErrorException { | |||||
| String url = "http://api.weixin.qq.com/wxa/getwxacodeunlimit"; | |||||
| public File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { | |||||
| WxMaWxcodeLimit wxMaWxcodeLimit = new WxMaWxcodeLimit(); | WxMaWxcodeLimit wxMaWxcodeLimit = new WxMaWxcodeLimit(); | ||||
| wxMaWxcodeLimit.setScene(scene); | wxMaWxcodeLimit.setScene(scene); | ||||
| wxMaWxcodeLimit.setPage(page); | wxMaWxcodeLimit.setPage(page); | ||||
| @@ -64,7 +62,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||||
| wxMaWxcodeLimit.setAutoColor(autoColor); | wxMaWxcodeLimit.setAutoColor(autoColor); | ||||
| wxMaWxcodeLimit.setLineColor(lineColor); | wxMaWxcodeLimit.setLineColor(lineColor); | ||||
| return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | ||||
| url, wxMaWxcodeLimit); | |||||
| GET_WXACODE_UNLIMIT_URL, wxMaWxcodeLimit); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -0,0 +1,42 @@ | |||||
| package cn.binarywang.wx.miniapp.bean; | |||||
| /** | |||||
| * <pre> | |||||
| * lineColor 包装类 | |||||
| * 用于描述二维码(小程序码)颜色(RGB参数值), | |||||
| * 详情请查看文档 https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html | |||||
| * </pre> | |||||
| */ | |||||
| public class WxMaCodeLineColor { | |||||
| private String r = "0", g = "0", b = "0"; | |||||
| public WxMaCodeLineColor(String r, String g, String b) { | |||||
| this.r = r; | |||||
| this.g = g; | |||||
| this.b = b; | |||||
| } | |||||
| public String getR() { | |||||
| return r; | |||||
| } | |||||
| public void setR(String r) { | |||||
| this.r = r; | |||||
| } | |||||
| public String getG() { | |||||
| return g; | |||||
| } | |||||
| public void setG(String g) { | |||||
| this.g = g; | |||||
| } | |||||
| public String getB() { | |||||
| return b; | |||||
| } | |||||
| public void setB(String b) { | |||||
| this.b = b; | |||||
| } | |||||
| } | |||||
| @@ -1,6 +1,5 @@ | |||||
| package cn.binarywang.wx.miniapp.bean; | package cn.binarywang.wx.miniapp.bean; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | |||||
| import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | ||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||
| @@ -19,7 +18,7 @@ public class WxMaWxcode extends WxMaQrcodeWrapper implements Serializable { | |||||
| private boolean autoColor = true; | private boolean autoColor = true; | ||||
| @SerializedName("line_color") | @SerializedName("line_color") | ||||
| private WxMaQrcodeService.LineColor lineColor = new WxMaQrcodeService.LineColor("0", "0", "0"); | |||||
| private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); | |||||
| public static WxMaWxcode fromJson(String json) { | public static WxMaWxcode fromJson(String json) { | ||||
| return WxMaGsonBuilder.create().fromJson(json, WxMaWxcode.class); | return WxMaGsonBuilder.create().fromJson(json, WxMaWxcode.class); | ||||
| @@ -53,11 +52,11 @@ public class WxMaWxcode extends WxMaQrcodeWrapper implements Serializable { | |||||
| this.autoColor = autoColor; | this.autoColor = autoColor; | ||||
| } | } | ||||
| public WxMaQrcodeService.LineColor getLineColor() { | |||||
| public WxMaCodeLineColor getLineColor() { | |||||
| return lineColor; | return lineColor; | ||||
| } | } | ||||
| public void setLineColor(WxMaQrcodeService.LineColor lineColor) { | |||||
| public void setLineColor(WxMaCodeLineColor lineColor) { | |||||
| this.lineColor = lineColor; | this.lineColor = lineColor; | ||||
| } | } | ||||
| @@ -1,6 +1,5 @@ | |||||
| package cn.binarywang.wx.miniapp.bean; | package cn.binarywang.wx.miniapp.bean; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | |||||
| import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | ||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||
| @@ -20,7 +19,7 @@ public class WxMaWxcodeLimit extends WxMaQrcodeWrapper implements Serializable { | |||||
| private boolean autoColor = true; | private boolean autoColor = true; | ||||
| @SerializedName("line_color") | @SerializedName("line_color") | ||||
| private WxMaQrcodeService.LineColor lineColor = new WxMaQrcodeService.LineColor("0", "0", "0"); | |||||
| private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); | |||||
| public static WxMaWxcodeLimit fromJson(String json) { | public static WxMaWxcodeLimit fromJson(String json) { | ||||
| return WxMaGsonBuilder.create().fromJson(json, WxMaWxcodeLimit.class); | return WxMaGsonBuilder.create().fromJson(json, WxMaWxcodeLimit.class); | ||||
| @@ -58,11 +57,11 @@ public class WxMaWxcodeLimit extends WxMaQrcodeWrapper implements Serializable { | |||||
| this.autoColor = autoColor; | this.autoColor = autoColor; | ||||
| } | } | ||||
| public WxMaQrcodeService.LineColor getLineColor() { | |||||
| public WxMaCodeLineColor getLineColor() { | |||||
| return lineColor; | return lineColor; | ||||
| } | } | ||||
| public void setLineColor(WxMaQrcodeService.LineColor lineColor) { | |||||
| public void setLineColor(WxMaCodeLineColor lineColor) { | |||||
| this.lineColor = lineColor; | this.lineColor = lineColor; | ||||
| } | } | ||||
| } | } | ||||