java对接顺丰接口查询物流


前提
丰桥是没有客服的,旁边的客服和群都是摆设,“同性交友会”罢了

准备

注册丰桥账号,申请开发者权限,这个的话是秒过,然后去申请接口

申请之后,如果没有月结卡号是没办法通过接口审核需要手动丰桥提问向客服反馈,如果只是路由查询的话,其他接口还是需要月结卡号,接口接入正式环境的审核还需要先在沙箱测试3次并成功,那个随便点2下就行。如果前面成功了,就会如下图

顺丰Java开发测评 深圳顺丰java待遇怎么样_java


附,丰桥提问即我的要提问

顺丰Java开发测评 深圳顺丰java待遇怎么样_丰桥_02


代码部分

值得一提的是,必须按照他的类型写 不然会有问题,后续补充问题

我写的如下,还需要官方提供的jar

final String CLIENT_CODE = "o";  //此处替换为您在丰桥平台获取的顾客编码
		final String CHECK_WORD = "o";//此处替换为您在丰桥平台获取的校验码
		EspServiceCode testService = EspServiceCode.EXP_RECE_SEARCH_ROUTES;//查路由
		final String CALL_URL_PROD = "https://sfapi.sf-express.com/std/service";
		CallExpressServiceTools client=CallExpressServiceTools.getInstance();

		Map<String, String> params = new HashMap<String, String>();
		String timeStamp = String.valueOf(System.currentTimeMillis());
		String msgData ="{\"trackingNumber\":[\"SF"+id+"\"],\"checkPhoneNo\":\""+phone+"\"}";//无月结卡号通过运单和手机后4位即可
		params.put("partnerID", CLIENT_CODE);  // 顾客编码 ,对应丰桥上获取的clientCode
		params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
		params.put("serviceCode",testService.getCode());// 接口服务码
		params.put("timestamp", timeStamp);
		params.put("msgData", msgData);
		params.put("msgDigest", client.getMsgDigest(msgData,timeStamp,CHECK_WORD));
		long startTime = System.currentTimeMillis();
		System.out.println("====调用请求:" + params.get("msgData"));
		String result = HttpClientUtil.post(CALL_URL_PROD, params);
		System.out.println("====调用丰桥的接口服务代码:" + String.valueOf(testService.getCode()) + " 接口耗时:"+ String.valueOf(System.currentTimeMillis()-startTime)+"====");
		System.out.println("===调用地址 ==="+CALL_URL_PROD);
		System.out.println("===顾客编码 ==="+CLIENT_CODE);
		System.out.println("===返回结果:" +result);

问题

顺丰Java开发测评 深圳顺丰java待遇怎么样_小程序_03


顺丰Java开发测评 深圳顺丰java待遇怎么样_小程序_04

这个接口服务码必须这么写,如果直接写成 String 类型 会提示你没有服务权限 属实拉胯

最后,他返回的Json 是个套中套格式,我也细心的帮各位贴出

System.out.println("===返回结果:" +result);
		com.gexin.fastjson.JSONObject info= JSON.parseObject(result);
		String apiResultData = info.getString("apiResultData");
		System.out.println("========="+apiResultData+"============");
		com.gexin.fastjson.JSONObject info1= JSON.parseObject(apiResultData);
		String msg = info1.getString("msgData");
		System.out.println("msgdata"+msg);
		com.gexin.fastjson.JSONObject info2= JSON.parseObject(msg);
		String routeResps = info2.getString("routeResps");
		System.out.println("routeResps"+routeResps.toString());

最后大致是这么个内容

routeResps[{"mailNo":"SF1334711867349","routes":[
{"acceptAddress":"上海市","acceptTime":"2021-01-30 11:20:22","remark":"顺丰速运 已收取快件","opCode":"50"},
{"acceptAddress":"上海市","acceptTime":"2021-01-30 16:29:16","remark":"快件在【上海青浦香花桥营业部】完成分拣,准备发往 【苏州千灯中转场】","opCode":"30"},
{"acceptAddress":"广州市","acceptTime":"2021-02-01 12:18:34","remark":"在官网\"运单资料&签收图\",可查看签收人信息","opCode":"8000"}]}]

最后的最后,还帮大家贴出小程序的物流模板

效果如图

顺丰Java开发测评 深圳顺丰java待遇怎么样_物流_05


代码

<template>
		<view class="shipping" >
		<view v-if="list.length==0">未发货或手机号单号错误</view>
				<view class="linehh" v-if="list.length>0"  :style="'height:'+xiantiaoHeight+'px;top:'+xiantiaoTop+'px;left:'+xiantiaoLeft+'px'"></view>
			<view class="ul" v-for="(item,index) in list" :key="index">
				<view class="li">
					<view class="time">
						<text class="timeday">{{item.day}}</text>
						<text class="timeh">{{item.time}}</text>
					</view>
					<view class="mmmm">
					
						<view class="yuan " :class="{act:index==0||index == list.length-1,first:index==0,end:index==list.length-1}"  >
 
						</view>
					</view>
 
					<view class="desc" :class="{black:index==0||index == list.length-1}"   >
						<text>{{item.desc}}</text>
					</view>
				</view>
			</view>
			<!-- <view class="btn" @click="">分享</view> -->
		</view>
		</view>

</template>
<script>
	import { wuliu } from '../../api/index'
	export default {
		data() {
			return {
				id:0,
				phone:0,
				xiantiaoHeight:0,
				xiantiaoLeft:0,
				xiantiaoTop:0,
				list:[],
				wuliuList:{
					time:'',
					day:'',
					desc:''
				},
				
		onLoad(options) {
			var that = this;
			 setTimeout(function(){
				 that.getHeight();
			 },2000)
			this.id = options.id
			this.phone = options.phone
			this.getInfo()
			console.log(this.id+"3333333333")
			this.chaxun()
		},
		onShareAppMessage() {},//小程序分享
		methods: {
          getHeight(){
			  const query = uni.createSelectorQuery();
			  query.select('.first').boundingClientRect()
			   query.select('.end').boundingClientRect()
			   var that =this;
			     query.exec(function (res) {
			         console.log(res); 
			         var xiantiaoHeight = 0;
			         if(res[1] !== null){
			           xiantiaoHeight = (res[1].top - res[0].top);
			         }
			  					console.log(res[0].left);
			  					console.log(res[0].top);
			  					console.log(xiantiaoHeight);
			          
			          that.xiantiaoHeight=xiantiaoHeight;
			           that.xiantiaoLeft= res[0].left + 4;
			            that.xiantiaoTop= res[0].top;
			       })
		  },
		async  chaxun(){
			var that = this
			 let json = await wuliu({
				  id : that.id,
				  phone :that.phone
			  })
			  this.list = json
			  this.list = this.list[0].routes
			  console.log(this.list)
			  for (var i = 0; i < this.list.length; i++) {
					var day = this.list[i].acceptTime
					var date = day.substring(5,10)
					var time = day.substring(11,16)
					var desc = this.list[i].remark
					this.list[i].day = date
					this.list[i].time = time
					this.list[i].desc = desc
			  }
			  console.log(this.list)
			 
			  
</script>



<style lang="scss">
	page {
		background: rgba(246, 246, 246, 1);
		padding-bottom: 120upx;
		font-family: PingFang SC;
		letter-spacing: 0.30000001192092896px;
	}
 
	// 物流列表
	.shipping {
		width: 94%;
		margin: 0 auto;
		background-color: #ffffff;
		padding: 30upx;
		margin-top: 20upx;
		border-radius: 10upx;
         .linehh {
			 position: absolute;
         	width: 2upx;
         	border-left: 2upx dotted rgba(176, 177, 183, 1);
         }
		.ul {
			.li {
				width: 100%;
				display: flex;
				height: auto;
                margin-top: 2upx;
				// .time:before {
				// 	/* 流程点的样式 */
				// 	content: '';
				// 	border: 3upx solid $base-color;
				// 	background-color: $base-color;
				// 	display: inline-block;
				// 	width: 16upx;
				// 	height: 16upx;
				// 	border-radius: 10upx;
				// 	margin-left: 120upx;
				// 	margin-right: 0upx
				// }
 
				.time {
 
					width: 16%;
					padding: 20upx 0upx;
					display: flex;
					flex-direction: column;
					align-items: center;
					font-family: PingFang SC;
					font-weight: bold;
					color: rgba(176, 177, 183, 1);
					 
 
					.timeday {
						font-size:28upx;
					}
 
					.timeh {
						font-size: 24upx;
					}
 
				}
 
				.mmmm {
					
                    position: relative;
					width: 10%;
					
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
 
					.yuan {
						position: absolute;
						left: 20upx;
						width: 20rpx;
						height: 20rpx;
						background: #dedede;
						border-radius: 50%;
						border: 3rpx solid #f2f2f2;
						&.act{
							background-color: #FD2E6F;
						}
					}
 
				}
 
				.desc {
					width: 74%;
					padding: 20upx 0upx;
					margin-left: 20upx;
					font-size:28upx;
					font-weight: 500;
					color: rgba(176, 177, 183, 1);
                    &.black{
						 color:rgba(34,36,49,1);;
					}
					text {}
				}
			}
		}
	}
 
</style>