Java 微信小程序-确认收货提醒接口 对接代码


微信小程序-确认收货提醒接口开发文档

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());
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值