文章目录
微信小程序-获取运力id列表get_delivery_list接口开发文档
POST https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list?access_token=XXX
一、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 lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.HashMap;
import java.util.List;
@SpringBootTest
@Slf4j
public class WeiXinApplicationTests {
/**
* 微信小程序-获取运力id列表get_delivery_list
* */
@Test
void test04(){
try {
String accessToken = "接口调用凭证accessToken";
String url = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list?access_token="+accessToken+"";
// 无参post请求
String result = HttpUtil.post(url, String.valueOf(new HashMap<String,Object>()));
JSONObject jsonObject = JSON.parseObject(result);
int errcode = jsonObject.getInteger("errcode");
if (errcode != 0) {
String errmsg = jsonObject.getString("errmsg");
String err = String.format("微信小程序-获取运力id列表get_delivery_list接口异常,code码:%s, msg:%s", errcode, errmsg);
log.error(err);
throw new CommonException(errcode, "微信小程序-获取运力id列表get_delivery_list接口异常:" + errmsg);
}
com.alibaba.fastjson.JSONArray deliveryList = jsonObject.getJSONArray("delivery_list");
List<JSONObject> list = deliveryList.toJavaList(JSONObject.class);
for (JSONObject o : list) {
String deliveryId = o.getString("delivery_id");
String deliveryName = o.getString("delivery_name");
System.out.println("o = " + o);
}
System.out.println("jsonObject = " + jsonObject);
} catch (Exception e) {
throw new CommonException(e.getMessage());
}
}
}