From 96b370ea014fda8c22978a6d1f04b44b75b5d9ac Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 29 Mar 2020 16:13:51 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1373=20=E5=A2=9E=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=9A=E4=B8=BB=E8=A6=81=E6=98=AF?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=8A=BD=E6=A0=B7=E6=95=B0=E6=8D=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E6=B6=88=E6=81=AF=E6=97=B6=E5=AF=B9=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=B1=9E=E6=80=A7=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaService.java | 42 +++++- .../wx/miniapp/api/impl/WxMaServiceImpl.java | 13 ++ .../wx/miniapp/bean/WxMaMessage.java | 9 ++ .../miniapp/api/impl/WxMaServiceImplTest.java | 139 +++++++++++++++++- 4 files changed, 198 insertions(+), 5 deletions(-) diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index 80150968d..072907ba1 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -22,6 +22,11 @@ public interface WxMaService { */ String GET_PAID_UNION_ID_URL = "https://api.weixin.qq.com/wxa/getpaidunionid"; + /** + * 导入抽样数据 + */ + String SET_DYNAMIC_DATA_URL = "https://api.weixin.qq.com/wxa/setdynamicdata"; + /** * 获取登录后的session信息. * @@ -29,6 +34,22 @@ public interface WxMaService { */ WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException; + /** + * 导入抽样数据 + *
+   * 第三方通过调用微信API,将数据写入到setdynamicdata这个API。每个Post数据包不超过5K,若数据过多可开多进(线)程并发导入数据(例如:数据量为十万量级可以开50个线程并行导数据)。
+   * 文档地址:https://wsad.weixin.qq.com/wsad/zh_CN/htmledition/widget-docs-v3/html/custom/quickstart/implement/import/index.html
+   * http请求方式:POST http(s)://api.weixin.qq.com/wxa/setdynamicdata?access_token=ACCESS_TOKEN
+   * 
+ * + * @param data 推送到微信后台的数据列表,该数据被微信用于流量分配,注意该字段为string类型而不是object + * @param lifespan 数据有效时间,秒为单位,一般为86400,一天一次导入的频率 + * @param scene 1代表用于搜索的数据 + * @param type 用于标识数据所属的服务类目 + * @throws WxErrorException . + */ + void setDynamicData(int lifespan, String type, int scene, String data) throws WxErrorException; + /** *
    * 验证消息的确来自微信服务器.
@@ -73,6 +94,8 @@ public interface WxMaService {
    * @param transactionId 非必填 微信支付订单号
    * @param mchId         非必填 微信支付分配的商户号,和商户订单号配合使用
    * @param outTradeNo    非必填  微信支付商户订单号,和商户号配合使用
+   * @return UnionId.
+   * @throws WxErrorException .
    */
   String getPaidUnionId(String openid, String transactionId, String mchId, String outTradeNo) throws WxErrorException;
 
@@ -97,6 +120,13 @@ public interface WxMaService {
    * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
    * 可以参考,{@link MediaUploadRequestExecutor}的实现方法
    * 
+ * + * @param . + * @param . + * @param data 参数或请求数据 + * @param executor 执行器 + * @param uri 接口请求地址 + * @return . */ T execute(RequestExecutor executor, String uri, E data) throws WxErrorException; @@ -105,6 +135,8 @@ public interface WxMaService { * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试. * 默认:1000ms * + * + * @param retrySleepMillis 重试等待毫秒数 */ void setRetrySleepMillis(int retrySleepMillis); @@ -113,6 +145,8 @@ public interface WxMaService { * 设置当微信系统响应系统繁忙时,最大重试次数. * 默认:5次 * + * + * @param maxRetryTimes 最大重试次数 */ void setMaxRetryTimes(int maxRetryTimes); @@ -125,6 +159,8 @@ public interface WxMaService { /** * 注入 {@link WxMaConfig} 的实现. + * + * @param wxConfigProvider config */ void setWxMaConfig(WxMaConfig wxConfigProvider); @@ -233,18 +269,22 @@ public interface WxMaService { /** * 请求http请求相关信息. + * + * @return . */ RequestHttp getRequestHttp(); /** * 获取物流助手接口服务对象 * - * @return + * @return . */ WxMaExpressService getExpressService(); /** * 获取云开发接口服务对象 + * + * @return . */ WxMaCloudService getCloudService(); } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java index 537364f28..9c1272eb3 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java @@ -4,7 +4,9 @@ import cn.binarywang.wx.miniapp.api.*; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.config.WxMaConfig; import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.google.gson.JsonParser; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.WxType; @@ -183,6 +185,17 @@ public class WxMaServiceImpl implements WxMaService, RequestHttpBinary Wang @@ -49,4 +50,134 @@ public class WxMaServiceImplTest { System.out.println(postResult); } + + @Test + public void testGetRequestHttpClient() { + } + + @Test + public void testGetRequestHttpProxy() { + } + + @Test + public void testGetRequestType() { + } + + @Test + public void testInitHttp() { + } + + @Test + public void testGetRequestHttp() { + } + + @Test + public void testGetAccessToken() { + } + + @Test + public void testJsCode2SessionInfo() { + } + + @Test + public void testSetDynamicData() throws WxErrorException { + this.wxService.setDynamicData(86400, "1000001", 1, + "{\"items\":[{\"stock_name\":\"腾讯控股\", \"stock_code\":\"00700\", \"stock_market\":\"hk\"}], \"attribute\":{\"count\":2, \"totalcount\": 100, \"id\": \"XXX\", \"seq\": 0}}"); + } + + @Test + public void testCheckSignature() { + } + + @Test + public void testTestGetAccessToken() { + } + + @Test + public void testGet() { + } + + @Test + public void testExecute() { + } + + @Test + public void testGetWxMaConfig() { + } + + @Test + public void testSetWxMaConfig() { + } + + @Test + public void testSetRetrySleepMillis() { + } + + @Test + public void testSetMaxRetryTimes() { + } + + @Test + public void testGetMsgService() { + } + + @Test + public void testGetMediaService() { + } + + @Test + public void testGetUserService() { + } + + @Test + public void testGetQrcodeService() { + } + + @Test + public void testGetTemplateService() { + } + + @Test + public void testGetSubscribeService() { + } + + @Test + public void testGetAnalysisService() { + } + + @Test + public void testGetCodeService() { + } + + @Test + public void testGetJsapiService() { + } + + @Test + public void testGetSettingService() { + } + + @Test + public void testGetShareService() { + } + + @Test + public void testGetRunService() { + } + + @Test + public void testGetSecCheckService() { + } + + @Test + public void testGetPluginService() { + } + + @Test + public void testGetExpressService() { + } + + @Test + public void testGetCloudService() { + } }