-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加小程序码支持,修正推送模板错误属性引发的NullPoint,增加TestCase #292
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
/** | ||
* <pre> | ||
* 二维码相关操作接口 | ||
* | ||
* 接口A(createWxCode)加上接口C(createQrcode),总共生成的码数量限制为100,000,请谨慎调用。 | ||
* | ||
* 文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html | ||
* </pre> | ||
* | ||
|
@@ -15,6 +18,7 @@ | |
public interface WxMaQrcodeService { | ||
|
||
/** | ||
* 接口C | ||
* <pre> | ||
* 获取小程序页面二维码 | ||
* 适用于需要的码数量较少的业务场景 | ||
|
@@ -27,4 +31,83 @@ public interface WxMaQrcodeService { | |
* @param width 默认430 二维码的宽度 | ||
*/ | ||
File createQrcode(String path, int width) throws WxErrorException; | ||
|
||
File createQrcode(String path) throws WxErrorException; | ||
|
||
/** | ||
* 接口A | ||
* 获取小程序码 | ||
* | ||
* @param path 不能为空,最大长度 128 字节 | ||
* @param width 默认430 二维码的宽度 | ||
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 | ||
* @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) throws WxErrorException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 未添加javadoc,其他方法一样 |
||
|
||
File createWxCode(String path) throws WxErrorException; | ||
|
||
/** | ||
* 接口B | ||
* 获取小程序码(永久有效、数量暂无限制) | ||
* <p> | ||
* 通过该接口生成的小程序码,永久有效,数量暂无限制。 | ||
* 用户扫描该码进入小程序后,将统一打开首页,开发者需在对应页面根据获取的码中 scene 字段的值,再做处理逻辑。 | ||
* 使用如下代码可以获取到二维码中的 scene 字段的值。 | ||
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode | ||
* | ||
* @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"} | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
File createWxCodeLimit(String scene, String page, int width, boolean autoColor, LineColor lineColor) throws WxErrorException; | ||
|
||
File createWxCodeLimit(String scene, String page) throws WxErrorException; | ||
|
||
/** | ||
* lineColor 包装类 | ||
* 用于描述二维码(小程序码)颜色(RGB参数值),详情请查看文档 | ||
*/ | ||
public static class LineColor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥这个静态内部类建在接口类里了? |
||
|
||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaQrcodeWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.binarywang.wx.miniapp.bean; | ||
|
||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | ||
|
||
/** | ||
* 微信二维码(小程序码)包装器 | ||
* Created by Element on 2017/7/27. | ||
*/ | ||
public abstract class WxMaQrcodeWrapper { | ||
|
||
@Override | ||
public String toString() { | ||
return WxMaGsonBuilder.create().toJson(this); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cn.binarywang.wx.miniapp.bean; | ||
|
||
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | ||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Created by Element on 2017/7/27. | ||
*/ | ||
public class WxMaWxcode extends WxMaQrcodeWrapper implements Serializable { | ||
|
||
private static final long serialVersionUID = 1287399621649210322L; | ||
private String path; | ||
private int width = 430; | ||
|
||
@SerializedName("auto_color") | ||
private boolean autoColor = true; | ||
|
||
@SerializedName("line_color") | ||
private WxMaQrcodeService.LineColor lineColor = new WxMaQrcodeService.LineColor("0", "0", "0"); | ||
|
||
public static WxMaWxcode fromJson(String json) { | ||
return WxMaGsonBuilder.create().fromJson(json, WxMaWxcode.class); | ||
} | ||
|
||
public static long getSerialVersionUID() { | ||
return serialVersionUID; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public void setWidth(int width) { | ||
this.width = width; | ||
} | ||
|
||
public boolean isAutoColor() { | ||
return autoColor; | ||
} | ||
|
||
public void setAutoColor(boolean autoColor) { | ||
this.autoColor = autoColor; | ||
} | ||
|
||
public WxMaQrcodeService.LineColor getLineColor() { | ||
return lineColor; | ||
} | ||
|
||
public void setLineColor(WxMaQrcodeService.LineColor lineColor) { | ||
this.lineColor = lineColor; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaWxcodeLimit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cn.binarywang.wx.miniapp.bean; | ||
|
||
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | ||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Created by Element on 2017/7/27. | ||
*/ | ||
public class WxMaWxcodeLimit extends WxMaQrcodeWrapper implements Serializable { | ||
private static final long serialVersionUID = 4782193774524960401L; | ||
private String scene; | ||
private String page; | ||
|
||
private int width = 430; | ||
|
||
@SerializedName("auto_color") | ||
private boolean autoColor = true; | ||
|
||
@SerializedName("line_color") | ||
private WxMaQrcodeService.LineColor lineColor = new WxMaQrcodeService.LineColor("0", "0", "0"); | ||
|
||
public static WxMaWxcodeLimit fromJson(String json) { | ||
return WxMaGsonBuilder.create().fromJson(json, WxMaWxcodeLimit.class); | ||
} | ||
|
||
public String getPage() { | ||
return page; | ||
} | ||
|
||
public void setPage(String page) { | ||
this.page = page; | ||
} | ||
|
||
public String getScene() { | ||
return scene; | ||
} | ||
|
||
public void setScene(String scene) { | ||
this.scene = scene; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public void setWidth(int width) { | ||
this.width = width; | ||
} | ||
|
||
public boolean isAutoColor() { | ||
return autoColor; | ||
} | ||
|
||
public void setAutoColor(boolean autoColor) { | ||
this.autoColor = autoColor; | ||
} | ||
|
||
public WxMaQrcodeService.LineColor getLineColor() { | ||
return lineColor; | ||
} | ||
|
||
public void setLineColor(WxMaQrcodeService.LineColor lineColor) { | ||
this.lineColor = lineColor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方的临时文件是供调用方进一步处理的,建议退出java时删掉