@@ -1,10 +1,10 @@ | |||
package cn.binarywang.wx.miniapp.api; | |||
import java.io.File; | |||
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import java.io.File; | |||
/** | |||
* <pre> | |||
* 二维码相关操作接口. | |||
@@ -40,12 +40,13 @@ public interface WxMaQrcodeService { | |||
/** | |||
* 接口A: 获取小程序码. | |||
* | |||
* @param path 不能为空,最大长度 128 字节 | |||
* @param width 默认430 二维码的宽度 | |||
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |||
* @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | |||
* @param path 不能为空,最大长度 128 字节 | |||
* @param width 默认430 二维码的宽度 | |||
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |||
* @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | |||
* @param is_hyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 | |||
*/ | |||
File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||
File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean is_hyaline) throws WxErrorException; | |||
File createWxaCode(String path, int width) throws WxErrorException; | |||
@@ -59,13 +60,15 @@ public interface WxMaQrcodeService { | |||
* 使用如下代码可以获取到二维码中的 scene 字段的值。 | |||
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode | |||
* </pre> | |||
* | |||
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) | |||
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面 | |||
* @param width 默认false 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |||
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | |||
* @param lineColor auth_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} | |||
* @param isHyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 | |||
*/ | |||
File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException; | |||
File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException; | |||
File createWxaCodeUnlimit(String scene, String page) throws WxErrorException; | |||
@@ -1,7 +1,5 @@ | |||
package cn.binarywang.wx.miniapp.api.impl; | |||
import java.io.File; | |||
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | |||
import cn.binarywang.wx.miniapp.api.WxMaService; | |||
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||
@@ -11,6 +9,8 @@ import cn.binarywang.wx.miniapp.bean.WxaCodeUnlimit; | |||
import cn.binarywang.wx.miniapp.util.http.QrCodeRequestExecutor; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import java.io.File; | |||
/** | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
@@ -33,28 +33,29 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||
} | |||
@Override | |||
public File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor) throws WxErrorException { | |||
public File createWxaCode(String path, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException { | |||
WxMaWxcode wxMaWxcode = new WxMaWxcode(); | |||
wxMaWxcode.setPath(path); | |||
wxMaWxcode.setWidth(width); | |||
wxMaWxcode.setAutoColor(autoColor); | |||
wxMaWxcode.setLineColor(lineColor); | |||
wxMaWxcode.setHyaline(isHyaline); | |||
return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | |||
GET_WXACODE_URL, wxMaWxcode); | |||
} | |||
@Override | |||
public File createWxaCode(String path, int width) throws WxErrorException { | |||
return this.createWxaCode(path, width, true, null); | |||
return this.createWxaCode(path, width, true, null, false); | |||
} | |||
@Override | |||
public File createWxaCode(String path) throws WxErrorException { | |||
return this.createWxaCode(path, 430, true, null); | |||
return this.createWxaCode(path, 430, true, null, false); | |||
} | |||
@Override | |||
public File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor) | |||
public File createWxaCodeUnlimit(String scene, String page, int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) | |||
throws WxErrorException { | |||
WxaCodeUnlimit wxaCodeUnlimit = new WxaCodeUnlimit(); | |||
wxaCodeUnlimit.setScene(scene); | |||
@@ -62,13 +63,14 @@ public class WxMaQrcodeServiceImpl implements WxMaQrcodeService { | |||
wxaCodeUnlimit.setWidth(width); | |||
wxaCodeUnlimit.setAutoColor(autoColor); | |||
wxaCodeUnlimit.setLineColor(lineColor); | |||
wxaCodeUnlimit.setHyaline(isHyaline); | |||
return this.wxMaService.execute(new QrCodeRequestExecutor(this.wxMaService.getRequestHttp()), | |||
GET_WXACODE_UNLIMIT_URL, wxaCodeUnlimit); | |||
} | |||
@Override | |||
public File createWxaCodeUnlimit(String scene, String page) throws WxErrorException { | |||
return this.createWxaCodeUnlimit(scene, page, 430, true, null); | |||
return this.createWxaCodeUnlimit(scene, page, 430, true, null, false); | |||
} | |||
} |
@@ -23,6 +23,9 @@ public class WxMaWxcode extends AbstractWxMaQrcodeWrapper implements Serializabl | |||
@SerializedName("auto_color") | |||
private boolean autoColor = true; | |||
@SerializedName("is_hyaline") | |||
private boolean isHyaline = false; | |||
@SerializedName("line_color") | |||
private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); | |||
@@ -1,12 +1,12 @@ | |||
package cn.binarywang.wx.miniapp.bean; | |||
import java.io.Serializable; | |||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | |||
import com.google.gson.annotations.SerializedName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import java.io.Serializable; | |||
/** | |||
* 小程序码接口B. | |||
* | |||
@@ -25,6 +25,9 @@ public class WxaCodeUnlimit extends AbstractWxMaQrcodeWrapper implements Seriali | |||
@SerializedName("auto_color") | |||
private boolean autoColor = true; | |||
@SerializedName("is_hyaline") | |||
private boolean isHyaline = false; | |||
@SerializedName("line_color") | |||
private WxMaCodeLineColor lineColor = new WxMaCodeLineColor("0", "0", "0"); | |||