wx小程序使用物流组件

接入前的准备工作
  • 配置小程序的业务域名(开发管理->业务域名)
    在这里插入图片描述

  • 在物流服务中开通查询组建
    在这里插入图片描述

  • 服务器域名配置(需加入物流接口域名白名单)

微信物流服务接口文档

在manifest.json中声明组建

"logisticsPlugin": {
				"version": "2.3.0",
				"provider": "插件的appId(账号设置->第三方设置->物流服务)"
			}

在需要的页面中引入

 // 引入插件
 	const plugin = requirePlugin("logisticsPlugin");
 	export default {

调用后端接口

  async searchDetail(){
		  let options={
			  openId:uni.getStorageSync("userInfo").openId,
			  phone:uni.getStorageSync("userInfo").telephone,
			  waybillId:this.orderInfo.deliveryNo,
			  mallOrder:this.orderInfo
			  
		  }
		 const {msg} =  await  api.post("/wechat/order/xxx",options);
		 console.log("获取物流轨迹token",msg);
		 plugin.openWaybillTracking({
		      			waybillToken: msg
		 		});		  
	  }
编写 java后端代码
  • 封装物流API请求
    /**
     * 配合物流组件查询物流信息
     * @return
     */
    public String getLogistics(String openId, String phone, String waybillId, MallGoods mallGoods,String wxPayNo,String deliveryId){
        String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
        String replaceUrl = tokenUrl.replace("{0}",appId).replace("{1}",secret);
        JSONObject tokenJson = JSONObject.parseObject(HttpUtils.sendGet(replaceUrl));
        String token =tokenJson.get("access_token").toString();

        String getUploadUrl = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/trace_waybill?access_token=" + token;
        JSONObject json = new JSONObject();
        json.put("openid",openId);
        json.put("receiver_phone",phone);
        json.put("trans_id",wxPayNo);
        json.put("delivery_id",deliveryId);
        json.put("waybill_id",waybillId);
        JSONObject goodsInfo = new JSONObject();
        JSONArray detailList = new JSONArray();
            JSONObject detail = new JSONObject();
            detail.put("goods_name",mallGoods.getName());
            detail.put("goods_img_url","");
            detailList.add(detail);

        goodsInfo.put("detail_list",detailList);
        json.put("goods_info",goodsInfo);
//            System.out.println(json.toString());
        JSONObject jsonObject = JSONObject.parseObject(HttpUtil.post(getUploadUrl,json.toString()));
//        tradeOrder.setWaybillToken(jsonObject.getString("waybill_token"));
        if (jsonObject.getString("errmsg").equals("ok")) {
            String tokens = jsonObject.getString("waybill_token");
            return tokens;
        }
        return null;
    }
展示结果

物流组建页面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值