文章目录
POST https://api.weixin.qq.com/wxa/sec/order/notify_confirm_receive?access_token=ACCESS_TOKEN
一、实体类
package com.xxx.cloud.weixin.admin.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 微信小程序-确认收货提醒接口vo
*
* @author hcx
*/
@Data
@Schema(description = "微信小程序-确认收货提醒接口vo")
public class WxTakeOverGoodsVo {
@Schema(description = "transaction_id")
private String transaction_id;
@Schema(description = "merchant_id")
private String merchant_id;
@Schema(description = "sub_merchant_id")
private String sub_merchant_id;
@Schema(description = "merchant_trade_no")
private String merchant_trade_no;
@Schema(description = "received_time")
@NotNull(message = "received_time不能为空")
private Integer received_time;
}
二、junit测试接口
package com.xxx.cloud.weixin.admin;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xxx.cloud.common.core.exception.CommonException;
import com.xxx.cloud.weixin.admin.vo.WxTakeOverGoodsVo;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@Slf4j
public class WeiXinApplicationTests {
/**
* 微信小程序-确认收货提醒接口-模拟入参
* */
private static WxTakeOverGoodsVo getWxTakeOverGoodsVo(){
WxTakeOverGoodsVo vo = new WxTakeOverGoodsVo();
vo.setMerchant_id("fake-mchid-123");
vo.setMerchant_trade_no("fake-tradeno-20221209132531-44");
vo.setReceived_time(1670829139);
vo.setSub_merchant_id("");
vo.setTransaction_id("fake-transid-20221209132531-44");
return vo;
}
/**
* 微信小程序-确认收货提醒接口
* */
@Test
void test02(){
try {
String accessToken = "接口调用凭证accessToken";
String url = "https://api.weixin.qq.com/wxa/sec/order/notify_confirm_receive?access_token="+accessToken+"";
/* 获取模拟入参 */
WxTakeOverGoodsVo vo = WeiXinApplicationTests.getWxTakeOverGoodsVo();
String param = JSONObject.toJSONString(vo);
System.out.println("入参 = " + param);
String result = HttpUtil.post(url, param);
JSONObject jsonObject = JSON.parseObject(result);
int errcode = jsonObject.getInteger("errcode");
if (errcode != 0) {
String errmsg = jsonObject.getString("errmsg");
String err = String.format("微信小程序-确认收货提醒接口异常,code码:%s, msg:%s", errcode, errmsg);
log.error(err);
throw new CommonException(errcode, "微信小程序-确认收货提醒接口异常:" + errmsg);
}
} catch (Exception e) {
throw new CommonException(e.getMessage());
}
}
}