1.新增微信用户创建自定义处理接口,2.新增微信订单关闭接口
This commit is contained in:
parent
052e220707
commit
d0a9d76148
@ -14,6 +14,7 @@ import ink.wgink.login.wechat.service.sign.IMiniappSignService;
|
||||
import ink.wgink.module.wechat.manager.MiniappManager;
|
||||
import ink.wgink.module.wechat.pojo.bos.miniapp.MiniappUserInfoBO;
|
||||
import ink.wgink.module.wechat.pojo.pos.miniapp.MiniappUserPO;
|
||||
import ink.wgink.module.wechat.service.miniapp.IMiniappUserCreateHandleService;
|
||||
import ink.wgink.module.wechat.service.miniapp.IMiniappUserService;
|
||||
import ink.wgink.properties.wechat.miniapp.MiniappProperties;
|
||||
import ink.wgink.service.user.pojo.pos.UserPO;
|
||||
@ -50,6 +51,8 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
|
||||
private IMiniappUserService miniappUserService;
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Autowired(required = false)
|
||||
private IMiniappUserCreateHandleService miniappUserCreateHandleService;
|
||||
|
||||
@Override
|
||||
public String defaultSign(MiniappLoginVO miniAppLoginVO) throws Exception {
|
||||
@ -67,21 +70,25 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
String resultJson = restTemplate.getForObject(url.toString(), String.class, params);
|
||||
MiniappUserInfoBO miniAppUserInfoBO = JSONObject.parseObject(resultJson, MiniappUserInfoBO.class);
|
||||
if (miniAppUserInfoBO == null) {
|
||||
MiniappUserInfoBO miniappUserInfoBO = JSONObject.parseObject(resultJson, MiniappUserInfoBO.class);
|
||||
if (miniappUserInfoBO == null) {
|
||||
throw new WechatUserInfoException("获取微信用户信息失败");
|
||||
}
|
||||
if (miniAppUserInfoBO.getErrcode() != null && miniAppUserInfoBO.getErrcode() != 0) {
|
||||
throw new WechatAccessTokenForUserException(String.format("获取用户信息失败,错误码:%s,错误信息:%s", miniAppUserInfoBO.getErrcode(), miniAppUserInfoBO.getErrmsg()));
|
||||
if (miniappUserInfoBO.getErrcode() != null && miniappUserInfoBO.getErrcode() != 0) {
|
||||
throw new WechatAccessTokenForUserException(String.format("获取用户信息失败,错误码:%s,错误信息:%s", miniappUserInfoBO.getErrcode(), miniappUserInfoBO.getErrmsg()));
|
||||
}
|
||||
LOG.debug("绑定用户");
|
||||
String userId = miniappUserService.createAndReturnUserId(miniappProperties.getAppKey(), miniAppUserInfoBO.getOpenid());
|
||||
String userId = miniappUserService.createAndReturnUserId(miniappProperties.getAppKey(), miniappUserInfoBO.getOpenid());
|
||||
UserPO userPO = userService.getPO(userId);
|
||||
if (userPO == null) {
|
||||
throw new SearchException("用户不存在");
|
||||
}
|
||||
// 加入管理队列
|
||||
MiniappManager.getInstance().addUser(userId, miniAppUserInfoBO);
|
||||
MiniappManager.getInstance().addUser(userId, miniappUserInfoBO);
|
||||
if (miniappUserCreateHandleService != null) {
|
||||
// 自定义新增处理
|
||||
miniappUserCreateHandleService.handle(userPO, miniappUserInfoBO.getOpenid());
|
||||
}
|
||||
return getMiniappToken(userPO);
|
||||
}
|
||||
|
||||
@ -147,7 +154,7 @@ public class MiniappSignServiceImpl extends BaseAppSignService implements IMinia
|
||||
/**
|
||||
* 获得小程序token
|
||||
*
|
||||
* @param userPO
|
||||
* @param userPO 用户对象
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
|
@ -5,8 +5,10 @@ import ink.wgink.module.wechat.pojo.pay.v3.PaySign;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.jsapi.pojo.PayPlaceOrder;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.order.OrderSearch;
|
||||
import ink.wgink.module.wechat.service.pay.v3.jsapi.IJsapiService;
|
||||
import ink.wgink.module.wechat.service.pay.v3.order.IOrderCloseService;
|
||||
import ink.wgink.module.wechat.service.pay.v3.order.IOrderSearchService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
import ink.wgink.util.OrderUtil;
|
||||
import io.swagger.annotations.*;
|
||||
import org.joda.time.DateTime;
|
||||
@ -30,6 +32,8 @@ public class MiniappPayDemoController {
|
||||
private IJsapiService jsapiService;
|
||||
@Autowired
|
||||
private IOrderSearchService orderSearchService;
|
||||
@Autowired
|
||||
private IOrderCloseService orderCloseService;
|
||||
|
||||
@ApiOperation(value = "下订单测试", notes = "下订单测试接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@ -57,7 +61,7 @@ public class MiniappPayDemoController {
|
||||
|
||||
@ApiOperation(value = "商家订单查询测试", notes = "商家订单查询测试接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header")
|
||||
@ApiImplicitParam(name = "businessOrderId", value = "商家订单ID", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("get-business-order/{businessOrderId}")
|
||||
@ -65,9 +69,9 @@ public class MiniappPayDemoController {
|
||||
return orderSearchService.getBusinessOrder(businessOrderId);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "商家订单查询测试", notes = "商家订单查询测试接口")
|
||||
@ApiOperation(value = "微信订单查询测试", notes = "微信订单查询测试接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header")
|
||||
@ApiImplicitParam(name = "transactionId", value = "微信订单ID", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("get-order/{transactionId}")
|
||||
@ -75,4 +79,15 @@ public class MiniappPayDemoController {
|
||||
return orderSearchService.getOrder(transactionId);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "商家订单关闭测试", notes = "商家订单关闭测试接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "businessOrderId", value = "商家订单ID", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("close-order/{businessOrderId}")
|
||||
public SuccessResult closeOrder(@PathVariable("businessOrderId") String businessOrderId) throws Exception {
|
||||
orderCloseService.closeOrder(businessOrderId);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package ink.wgink.module.wechat.pojo.pay.v3.order;
|
||||
|
||||
/**
|
||||
* @ClassName: OrderClose
|
||||
* @Description: 订单关闭
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/30 5:19 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class OrderClose {
|
||||
|
||||
private String mchid;
|
||||
|
||||
public String getMchid() {
|
||||
return mchid == null ? "" : mchid.trim();
|
||||
}
|
||||
|
||||
public void setMchid(String mchid) {
|
||||
this.mchid = mchid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"mchid\":\"")
|
||||
.append(mchid).append('\"');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package ink.wgink.module.wechat.request.pay.v3.order;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.PayErrorResponse;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.order.OrderClose;
|
||||
import ink.wgink.module.wechat.request.pay.v3.AbstractPayRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
/**
|
||||
* @ClassName: OrderClosePayRequest
|
||||
* @Description: 订单关闭
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/30 5:19 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class OrderClosePayRequestImpl extends AbstractPayRequest<OrderClose, JSONObject, String> {
|
||||
|
||||
@Override
|
||||
public JSONObject bodyJson(OrderClose orderClose) {
|
||||
JSONObject bodyJsonObject = new JSONObject();
|
||||
bodyJsonObject.put("mchid", orderClose.getMchid());
|
||||
return bodyJsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String response(ResponseEntity<String> responseEntity) {
|
||||
if (responseEntity.getStatusCodeValue() == HttpStatus.NO_CONTENT.value()) {
|
||||
return "";
|
||||
} else if (responseEntity.getStatusCodeValue() == HttpStatus.ACCEPTED.value()) {
|
||||
throw new SystemException("用户支付中,订单无法关闭,请等待5秒后查看支付结果");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(HttpClientErrorException e) {
|
||||
LOG.debug("Response error status code:{}", e.getStatusCode());
|
||||
PayErrorResponse payErrorResponse = JSONObject.parseObject(e.getResponseBodyAsString(), PayErrorResponse.class);
|
||||
LOG.debug("Response error detail: {}", payErrorResponse.getDetail());
|
||||
throw new SystemException(payErrorResponse.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package ink.wgink.module.wechat.service.miniapp;
|
||||
|
||||
import ink.wgink.service.user.pojo.pos.UserPO;
|
||||
|
||||
/**
|
||||
* @ClassName: IMiniappUserCreateCallbackService
|
||||
* @Description: 小程序用户创建回调
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/30 5:50 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IMiniappUserCreateHandleService {
|
||||
|
||||
/**
|
||||
* 用户新增后的处理
|
||||
*
|
||||
* @param userPO 用户对象
|
||||
* @param openid 小程序用户openid
|
||||
* @throws Exception
|
||||
*/
|
||||
void handle(UserPO userPO, String openid) throws Exception;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ink.wgink.module.wechat.service.pay.v3.order;
|
||||
|
||||
/**
|
||||
* @ClassName: IOrderCloseService
|
||||
* @Description: 订单关闭
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/30 5:30 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IOrderCloseService {
|
||||
|
||||
/**
|
||||
* 关闭订单
|
||||
*
|
||||
* @param businessOrderId 订单ID
|
||||
*/
|
||||
void closeOrder(String businessOrderId) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package ink.wgink.module.wechat.service.pay.v3.order.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.module.wechat.enums.PayAuthorizationTypeEnum;
|
||||
import ink.wgink.module.wechat.pojo.pay.v3.order.OrderClose;
|
||||
import ink.wgink.module.wechat.request.pay.v3.order.OrderClosePayRequestImpl;
|
||||
import ink.wgink.module.wechat.service.pay.BasePayService;
|
||||
import ink.wgink.module.wechat.service.pay.v3.order.IOrderCloseService;
|
||||
import ink.wgink.properties.wechat.pay.v3.PayProperties;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
* @ClassName: OrderCloseServiceImpl
|
||||
* @Description: 订单关闭
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/30 5:30 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class OrderCloseServiceImpl extends BasePayService implements IOrderCloseService {
|
||||
|
||||
@Autowired
|
||||
private PayProperties payProperties;
|
||||
|
||||
@Override
|
||||
public void closeOrder(String businessOrderId) throws Exception {
|
||||
if (StringUtils.isBlank(businessOrderId)) {
|
||||
throw new ParamsException("订单不能为空");
|
||||
}
|
||||
OrderClose orderClose = new OrderClose();
|
||||
orderClose.setMchid(payProperties.getMchid());
|
||||
|
||||
String urlSuffix = "/v3/pay/transactions/out-trade-no/" + businessOrderId + "/close";
|
||||
OrderClosePayRequestImpl orderClosePayRequest = new OrderClosePayRequestImpl();
|
||||
String url = getPayBaseUrl() + urlSuffix;
|
||||
String serialNumber = getSerialNumber();
|
||||
JSONObject body = orderClosePayRequest.bodyJson(orderClose);
|
||||
String authorization = getAuthorization(RequestMethod.POST, urlSuffix, serialNumber, payProperties, body.toString(), PayAuthorizationTypeEnum.WECHATPAY2_SHA256_RSA2048);
|
||||
orderClosePayRequest.post(url, authorization, serialNumber, body);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user