-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d36b4d
commit 60663f2
Showing
10 changed files
with
254 additions
and
4 deletions.
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
46 changes: 46 additions & 0 deletions
46
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopRegisterService.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,46 @@ | ||
package cn.binarywang.wx.miniapp.api; | ||
|
||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; | ||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; | ||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; | ||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
|
||
/** | ||
* 小程序交易组件-申请接入服务 | ||
* | ||
* @author liming1019 | ||
*/ | ||
public interface WxMaShopRegisterService { | ||
/** | ||
* 接入申请 | ||
* | ||
* @return WxMaShopBaseResponse | ||
* @throws WxErrorException | ||
*/ | ||
WxMaShopBaseResponse registerApply() throws WxErrorException; | ||
|
||
/** | ||
* 获取接入状态 | ||
* | ||
* @return WxMaShopRegisterCheckResponse | ||
* @throws WxErrorException | ||
*/ | ||
WxMaShopRegisterCheckResponse registerCheck() throws WxErrorException; | ||
|
||
/** | ||
* 完成接入任务 | ||
* | ||
* @return WxMaShopBaseResponse | ||
* @throws WxErrorException | ||
*/ | ||
WxMaShopBaseResponse registerFinishAccessInfo(WxMaShopRegisterFinishAccessInfoRequest request) throws WxErrorException; | ||
|
||
/** | ||
* 场景接入申请 | ||
* | ||
* @return WxMaShopBaseResponse | ||
* @throws WxErrorException | ||
*/ | ||
WxMaShopBaseResponse registerApplyScene(WxMaShopRegisterApplySceneRequest request) throws WxErrorException; | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.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.api.impl; | ||
|
||
import cn.binarywang.wx.miniapp.api.WxMaService; | ||
import cn.binarywang.wx.miniapp.api.WxMaShopRegisterService; | ||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; | ||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; | ||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; | ||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse; | ||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; | ||
import com.google.gson.JsonObject; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import me.chanjar.weixin.common.enums.WxType; | ||
import me.chanjar.weixin.common.error.WxError; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.common.util.json.GsonParser; | ||
|
||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Register.*; | ||
|
||
/** | ||
* @author liming1019 | ||
*/ | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class WxMaShopRegisterServiceImpl implements WxMaShopRegisterService { | ||
private static final String ERR_CODE = "errcode"; | ||
private final WxMaService wxMaService; | ||
|
||
@Override | ||
public WxMaShopBaseResponse registerApply() throws WxErrorException { | ||
String responseContent = this.wxMaService.post(REGISTER_APPLY, new JsonObject()); | ||
JsonObject jsonObject = GsonParser.parse(responseContent); | ||
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||
} | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); | ||
} | ||
|
||
@Override | ||
public WxMaShopRegisterCheckResponse registerCheck() throws WxErrorException { | ||
String responseContent = this.wxMaService.post(REGISTER_CHECK, new JsonObject()); | ||
JsonObject jsonObject = GsonParser.parse(responseContent); | ||
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||
} | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopRegisterCheckResponse.class); | ||
} | ||
|
||
@Override | ||
public WxMaShopBaseResponse registerFinishAccessInfo(WxMaShopRegisterFinishAccessInfoRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(REGISTER_FINISH_ACCESS_INFO, request); | ||
JsonObject jsonObject = GsonParser.parse(responseContent); | ||
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||
} | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); | ||
} | ||
|
||
@Override | ||
public WxMaShopBaseResponse registerApplyScene(WxMaShopRegisterApplySceneRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(REGISTER_APPLY_SCENE, request); | ||
JsonObject jsonObject = GsonParser.parse(responseContent); | ||
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { | ||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); | ||
} | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...in/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterApplySceneRequest.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,22 @@ | ||
package cn.binarywang.wx.miniapp.bean.shop.request; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author liming1019 | ||
* @date 2021/8/6 | ||
*/ | ||
@Data | ||
public class WxMaShopRegisterApplySceneRequest implements Serializable { | ||
|
||
private static final long serialVersionUID = -3008686013597621522L; | ||
/** | ||
* 1:视频号、公众号场景 | ||
*/ | ||
@SerializedName("scene_group_id") | ||
private Long sceneGroupId; | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
...a/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterFinishAccessInfoRequest.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,21 @@ | ||
package cn.binarywang.wx.miniapp.bean.shop.request; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author liming1019 | ||
* @date 2021/8/6 | ||
*/ | ||
@Data | ||
public class WxMaShopRegisterFinishAccessInfoRequest implements Serializable { | ||
private static final long serialVersionUID = 8679586799807671563L; | ||
/** | ||
* 6:完成spu接口,7:完成订单接口,8:完成物流接口,9:完成售后接口,10:测试完成,11:发版完成 | ||
*/ | ||
@SerializedName("access_info_item") | ||
private Long accessInfoItem; | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
.../main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopRegisterCheckResponse.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,22 @@ | ||
package cn.binarywang.wx.miniapp.bean.shop.response; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author liming1019 | ||
* @date 2021/8/5 | ||
*/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class WxMaShopRegisterCheckResponse extends WxMaShopBaseResponse implements Serializable { | ||
|
||
private static final long serialVersionUID = 9061844525630614116L; | ||
|
||
@SerializedName("data") | ||
private JsonObject data; | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...iapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImplTest.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,51 @@ | ||
package cn.binarywang.wx.miniapp.api.impl; | ||
|
||
import cn.binarywang.wx.miniapp.api.WxMaService; | ||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; | ||
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; | ||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; | ||
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse; | ||
import cn.binarywang.wx.miniapp.test.ApiTestModule; | ||
import com.google.inject.Inject; | ||
import org.testng.annotations.Guice; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author liming1019 | ||
*/ | ||
@Test | ||
@Guice(modules = ApiTestModule.class) | ||
public class WxMaShopRegisterServiceImplTest { | ||
@Inject | ||
private WxMaService wxService; | ||
|
||
@Test | ||
public void testRegisterApply() throws Exception { | ||
WxMaShopBaseResponse response = this.wxService.getShopRegisterService().registerApply(); | ||
assertThat(response).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void testRegisterCheck() throws Exception { | ||
WxMaShopRegisterCheckResponse response = this.wxService.getShopRegisterService().registerCheck(); | ||
assertThat(response).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void testRegisterFinishAccessInfo() throws Exception { | ||
WxMaShopRegisterFinishAccessInfoRequest request = new WxMaShopRegisterFinishAccessInfoRequest(); | ||
request.setAccessInfoItem(6L); | ||
WxMaShopBaseResponse response = this.wxService.getShopRegisterService().registerFinishAccessInfo(request); | ||
assertThat(response).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void testRegisterApplyScene() throws Exception { | ||
WxMaShopRegisterApplySceneRequest request = new WxMaShopRegisterApplySceneRequest(); | ||
request.setSceneGroupId(1L); | ||
WxMaShopBaseResponse response = this.wxService.getShopRegisterService().registerApplyScene(request); | ||
assertThat(response).isNotNull(); | ||
} | ||
} |