@@ -1,15 +1,15 @@ | |||||
package cn.binarywang.wx.miniapp.api; | package cn.binarywang.wx.miniapp.api; | ||||
import java.io.File; | |||||
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | 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; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 二维码相关操作接口. | * 二维码相关操作接口. | ||||
* | * | ||||
* 接口A(createWxCode)加上接口C(createQrcode),总共生成的码数量限制为100,000,请谨慎调用。 | |||||
* 接口A(createWxaCode)加上接口C(createQrcode),总共生成的码数量限制为100,000,请谨慎调用。 | |||||
* | * | ||||
* 文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html | * 文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html | ||||
* </pre> | * </pre> | ||||
@@ -45,11 +45,11 @@ public interface WxMaQrcodeService { | |||||
* @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"} | ||||
*/ | */ | ||||
File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||||
File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||||
File createWxCode(String path, int width) throws WxErrorException; | |||||
File createWxaCode(String path, int width) throws WxErrorException; | |||||
File createWxCode(String path) throws WxErrorException; | |||||
File createWxaCode(String path) throws WxErrorException; | |||||
/** | /** | ||||
* 接口B: 获取小程序码(永久有效、数量暂无限制). | * 接口B: 获取小程序码(永久有效、数量暂无限制). | ||||
@@ -65,8 +65,8 @@ public interface WxMaQrcodeService { | |||||
* @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"} | ||||
*/ | */ | ||||
File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||||
File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||||
File createWxCodeLimit(String scene, String page) throws WxErrorException; | |||||
File createWxaCodeUnlimit(String scene, String page) throws WxErrorException; | |||||
} | } |
@@ -1,16 +1,16 @@ | |||||
package cn.binarywang.wx.miniapp.api.impl; | package cn.binarywang.wx.miniapp.api.impl; | ||||
import java.io.File; | |||||
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.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.WxaCodeUnlimit; | |||||
import cn.binarywang.wx.miniapp.util.http.QrCodeRequestExecutor; | import cn.binarywang.wx.miniapp.util.http.QrCodeRequestExecutor; | ||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import java.io.File; | |||||
/** | /** | ||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
*/ | */ | ||||
@@ -33,7 +33,7 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||||
} | } | ||||
@Override | @Override | ||||
public File createWxCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { | |||||
public File createWxaCode(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); | ||||
@@ -44,31 +44,31 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||||
} | } | ||||
@Override | @Override | ||||
public File createWxCode(String path, int width) throws WxErrorException { | |||||
return this.createWxCode(path, width, true, null); | |||||
public File createWxaCode(String path, int width) throws WxErrorException { | |||||
return this.createWxaCode(path, width, true, null); | |||||
} | } | ||||
@Override | @Override | ||||
public File createWxCode(String path) throws WxErrorException { | |||||
return this.createWxCode(path, 430, true, null); | |||||
public File createWxaCode(String path) throws WxErrorException { | |||||
return this.createWxaCode(path, 430, true, null); | |||||
} | } | ||||
@Override | @Override | ||||
public File createWxCodeLimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) | |||||
public File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) | |||||
throws WxErrorException { | throws WxErrorException { | ||||
WxMaWxcodeLimit wxMaWxcodeLimit = new WxMaWxcodeLimit(); | |||||
wxMaWxcodeLimit.setScene(scene); | |||||
wxMaWxcodeLimit.setPage(page); | |||||
wxMaWxcodeLimit.setWidth(width); | |||||
wxMaWxcodeLimit.setAutoColor(autoColor); | |||||
wxMaWxcodeLimit.setLineColor(lineColor); | |||||
WxaCodeUnlimit wxaCodeUnlimit = new WxaCodeUnlimit(); | |||||
wxaCodeUnlimit.setScene(scene); | |||||
wxaCodeUnlimit.setPage(page); | |||||
wxaCodeUnlimit.setWidth(width); | |||||
wxaCodeUnlimit.setAutoColor(autoColor); | |||||
wxaCodeUnlimit.setLineColor(lineColor); | |||||
return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | ||||
GET_WXACODE_UNLIMIT_URL, wxMaWxcodeLimit); | |||||
GET_WXACODE_UNLIMIT_URL, wxaCodeUnlimit); | |||||
} | } | ||||
@Override | @Override | ||||
public File createWxCodeLimit(String scene, String page) throws WxErrorException { | |||||
return this.createWxCodeLimit(scene, page, 430, true, null); | |||||
public File createWxaCodeUnlimit(String scene, String page) throws WxErrorException { | |||||
return this.createWxaCodeUnlimit(scene, page, 430, true, null); | |||||
} | } | ||||
} | } |
@@ -1,12 +1,12 @@ | |||||
package cn.binarywang.wx.miniapp.bean; | package cn.binarywang.wx.miniapp.bean; | ||||
import java.io.Serializable; | |||||
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; | ||||
import lombok.Data; | import lombok.Data; | ||||
import lombok.EqualsAndHashCode; | import lombok.EqualsAndHashCode; | ||||
import java.io.Serializable; | |||||
/** | /** | ||||
* 小程序码接口B. | * 小程序码接口B. | ||||
* | * | ||||
@@ -15,7 +15,7 @@ import java.io.Serializable; | |||||
*/ | */ | ||||
@Data | @Data | ||||
@EqualsAndHashCode(callSuper = false) | @EqualsAndHashCode(callSuper = false) | ||||
public class WxMaWxcodeLimit extends AbstractWxMaQrcodeWrapper implements Serializable { | |||||
public class WxaCodeUnlimit extends AbstractWxMaQrcodeWrapper implements Serializable { | |||||
private static final long serialVersionUID = 4782193774524960401L; | private static final long serialVersionUID = 4782193774524960401L; | ||||
private String scene; | private String scene; | ||||
private String page; | private String page; | ||||
@@ -28,8 +28,8 @@ public class WxMaWxcodeLimit extends AbstractWxMaQrcodeWrapper implements Serial | |||||
@SerializedName("line_color") | @SerializedName("line_color") | ||||
private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); | private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); | ||||
public static WxMaWxcodeLimit fromJson(String json) { | |||||
return WxMaGsonBuilder.create().fromJson(json, WxMaWxcodeLimit.class); | |||||
public static WxaCodeUnlimit fromJson(String json) { | |||||
return WxMaGsonBuilder.create().fromJson(json, WxaCodeUnlimit.class); | |||||
} | } | ||||
} | } |
@@ -1,12 +1,12 @@ | |||||
package cn.binarywang.wx.miniapp.api.impl; | package cn.binarywang.wx.miniapp.api.impl; | ||||
import java.io.File; | |||||
import org.testng.annotations.*; | |||||
import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
import cn.binarywang.wx.miniapp.test.ApiTestModule; | import cn.binarywang.wx.miniapp.test.ApiTestModule; | ||||
import com.google.inject.Inject; | import com.google.inject.Inject; | ||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import java.io.File; | |||||
/** | /** | ||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
@@ -15,7 +15,7 @@ import java.io.File; | |||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
public class WxMaQrcodeServiceImplTest { | public class WxMaQrcodeServiceImplTest { | ||||
@Inject | @Inject | ||||
protected WxMaService wxService; | |||||
private WxMaService wxService; | |||||
@Test | @Test | ||||
public void testCreateQrCode() throws Exception { | public void testCreateQrCode() throws Exception { | ||||
@@ -24,14 +24,14 @@ public class WxMaQrcodeServiceImplTest { | |||||
} | } | ||||
@Test | @Test | ||||
public void testCreateWxCode() throws Exception { | |||||
final File wxCode = this.wxService.getQrcodeService().createWxCode("111", 122); | |||||
public void testCreateWxaCode() throws Exception { | |||||
final File wxCode = this.wxService.getQrcodeService().createWxaCode("111", 122); | |||||
System.out.println(wxCode); | System.out.println(wxCode); | ||||
} | } | ||||
@Test | @Test | ||||
public void testCreateWxCodeLimit() throws Exception { | |||||
final File wxCode = this.wxService.getQrcodeService().createWxCodeLimit("111", null); | |||||
public void testCreateWxaCodeUnlimit() throws Exception { | |||||
final File wxCode = this.wxService.getQrcodeService().createWxaCodeUnlimit("111", null); | |||||
System.out.println(wxCode); | System.out.println(wxCode); | ||||
} | } | ||||