mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-27 11:53:48 +08:00
🎨 修复完善获取 NFC 的小程序 scheme 接口
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package cn.binarywang.wx.miniapp.api;
|
package cn.binarywang.wx.miniapp.api;
|
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateNfcSchemeRequest;
|
||||||
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
|
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
|
||||||
@ -27,5 +28,5 @@ public interface WxMaSchemeService {
|
|||||||
* @param request 请求参数
|
* @param request 请求参数
|
||||||
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
||||||
*/
|
*/
|
||||||
String generateNFC(WxMaGenerateSchemeRequest request) throws WxErrorException;
|
String generateNFC(WxMaGenerateNfcSchemeRequest request) throws WxErrorException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
|||||||
|
|
||||||
import cn.binarywang.wx.miniapp.api.WxMaSchemeService;
|
import cn.binarywang.wx.miniapp.api.WxMaSchemeService;
|
||||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
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.bean.scheme.WxMaGenerateSchemeRequest;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -47,7 +48,7 @@ public class WxMaSchemeServiceImpl implements WxMaSchemeService {
|
|||||||
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
|
||||||
*/
|
*/
|
||||||
@Override
|
@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());
|
String responseContent = this.wxMaService.post(GENERATE_NFC_SCHEME_URL, request.toJson());
|
||||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||||
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
|
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
|
||||||
|
|||||||
@ -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 {
|
||||||
|
/**
|
||||||
|
* 跳转到的目标小程序信息。
|
||||||
|
* <pre>
|
||||||
|
* 是否必填:否
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SerializedName("jump_wxa")
|
||||||
|
private JumpWxa jumpWxa;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scheme对应的设备model_id
|
||||||
|
* <pre>
|
||||||
|
* 是否必填:是
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SerializedName("model_id")
|
||||||
|
private String modelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scheme对应的设备sn,仅一机一码时填写
|
||||||
|
* <pre>
|
||||||
|
* 是否必填:否
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SerializedName("sn")
|
||||||
|
private String sn;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder(builderMethodName = "newBuilder")
|
||||||
|
public static class JumpWxa {
|
||||||
|
/**
|
||||||
|
* 通过scheme码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带query。path为空时会跳转小程序主页。
|
||||||
|
* <pre>
|
||||||
|
* 是否必填:是
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SerializedName("path")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过scheme码进入小程序时的query,最大128个字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~
|
||||||
|
* 返回值
|
||||||
|
* <pre>
|
||||||
|
* 是否必填:是
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SerializedName("query")
|
||||||
|
private String query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 要打开的小程序版本。正式版为"release",体验版为"trial",开发版为"develop"默认值:release
|
||||||
|
*/
|
||||||
|
@SerializedName("env_version")
|
||||||
|
private String envVersion = "release";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return WxMaGsonBuilder.create().toJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package cn.binarywang.wx.miniapp.api.impl;
|
package cn.binarywang.wx.miniapp.api.impl;
|
||||||
|
|
||||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
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.bean.scheme.WxMaGenerateSchemeRequest;
|
||||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@ -37,4 +38,21 @@ public class WxMaSchemeServiceImplTest {
|
|||||||
System.out.println("generate:");
|
System.out.println("generate:");
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user