diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSchemeService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSchemeService.java index 6d1ef97d7..2526ee0d9 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSchemeService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSchemeService.java @@ -1,5 +1,6 @@ package cn.binarywang.wx.miniapp.api; +import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateNfcSchemeRequest; import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest; import me.chanjar.weixin.common.error.WxErrorException; @@ -27,5 +28,5 @@ public interface WxMaSchemeService { * @param request 请求参数 * @throws WxErrorException 生成失败时抛出,具体错误码请看文档 */ - String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException; + String generateNFC(WxMaGenerateNfcSchemeRequest request) throws WxErrorException; } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java index 5d6cd38f5..bf0976f0a 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java @@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl; import cn.binarywang.wx.miniapp.api.WxMaSchemeService; import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateNfcSchemeRequest; import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest; import com.google.gson.JsonObject; import lombok.AllArgsConstructor; @@ -47,7 +48,7 @@ public class WxMaSchemeServiceImpl implements WxMaSchemeService { * @throws WxErrorException 生成失败时抛出,具体错误码请看文档 */ @Override - public String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException { + public String generateNFC(WxMaGenerateNfcSchemeRequest request) throws WxErrorException { String responseContent = this.wxMaService.post(GENERATE_NFC_SCHEME_URL, request.toJson()); JsonObject jsonObject = GsonParser.parse(responseContent); if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) { diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/scheme/WxMaGenerateNfcSchemeRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/scheme/WxMaGenerateNfcSchemeRequest.java new file mode 100644 index 000000000..73d4e4a6d --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/scheme/WxMaGenerateNfcSchemeRequest.java @@ -0,0 +1,75 @@ +package cn.binarywang.wx.miniapp.bean.scheme; + +import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +/** + * @author : lyt + * created on : 2023-07-31 + */ +@Data +@Builder(builderMethodName = "newBuilder") +public class WxMaGenerateNfcSchemeRequest { + /** + * 跳转到的目标小程序信息。 + *
+ * 是否必填:否 + *+ */ + @SerializedName("jump_wxa") + private JumpWxa jumpWxa; + + /** + * scheme对应的设备model_id + *
+ * 是否必填:是 + *+ */ + @SerializedName("model_id") + private String modelId; + + /** + * scheme对应的设备sn,仅一机一码时填写 + *
+ * 是否必填:否 + *+ */ + @SerializedName("sn") + private String sn; + + @Data + @Builder(builderMethodName = "newBuilder") + public static class JumpWxa { + /** + * 通过scheme码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带query。path为空时会跳转小程序主页。 + *
+ * 是否必填:是 + *+ */ + @SerializedName("path") + private String path; + + /** + * 通过scheme码进入小程序时的query,最大128个字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~ + * 返回值 + *
+ * 是否必填:是 + *+ */ + @SerializedName("query") + private String query; + + /** + * 要打开的小程序版本。正式版为"release",体验版为"trial",开发版为"develop"默认值:release + */ + @SerializedName("env_version") + private String envVersion = "release"; + } + + public String toJson() { + return WxMaGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImplTest.java index 8fa3b1310..07c0c8395 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImplTest.java @@ -1,6 +1,7 @@ package cn.binarywang.wx.miniapp.api.impl; import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateNfcSchemeRequest; import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest; import cn.binarywang.wx.miniapp.test.ApiTestModule; import com.google.inject.Inject; @@ -37,4 +38,21 @@ public class WxMaSchemeServiceImplTest { System.out.println("generate:"); System.out.println(generate); } + + @Test + public void testGenerateNfc() throws WxErrorException { + final Date date = DateUtils.addMinutes(new Date(), 20); // 20分钟后失效 + final long expireTime = date.getTime() / 1000; + final String generate = this.wxService.getWxMaSchemeService().generateNFC(WxMaGenerateNfcSchemeRequest.newBuilder() + .jumpWxa(WxMaGenerateNfcSchemeRequest.JumpWxa.newBuilder() +// .path("/pages/productView/editPhone/editPhone") // 都可以 + .path("pages/productView/editPhone/editPhone") // + .query("") + .build()) + .modelId("") // 到期失效 + .sn("") // 失效时间 + .build()); + System.out.println("generate:"); + System.out.println(generate); + } }