• 首页
  • 栏目
  • ERP
  • 拼多多电子面单云打印接口对接 (跨境erp应用,电子面单应用)[拼多多获取电子面单,拼多多面单打印]

拼多多电子面单云打印接口对接 (跨境erp应用,电子面单应用)[拼多多获取电子面单,拼多多面单打印]

  • 2021-01-11
  • Admin

一.简介
使用拼多多开放平台提供的拼多多电子面单功能。
拼多多开放平台提供的这两个应用的区别:
1.在于业务权限方面,跨境erp权限很多具体可以在开放平台看到,其中就包括了获取电子面单,而电子面单应用呢就只限于获取电子面单的一系列。
2.erp在测试过程中就可以给应用授权,电子面单需要上线才能授权
3.获取code(授权)的拼接方式不同如图:

在这里插入图片描述
同时erp需要店铺授权,电子面单不需要 电子面单如图:需要的是拼多多电子面单账户
注册地址:拼多多电子面单平台地址(注册应用授权所要的账号)
注册好后,登入找到如下图位置:
在这里插入图片描述
把上图的账号加进来就好
在这里插入图片描述
erp如图: 这里加的是拼多多商家后台的账号(具体过程在下文 ,请完后看,这里只是说下区别)
在这里插入图片描述
其他流程几乎相同 获取面单的代码也一致 两者间代码共用,只需要更换相应的 clientId,clientSecret ,以及不同授权码获取到的token 即可

二.流程
1.拼多多开放平台地址:拼多多开放平台地址
2.找到文档 如图:
在这里插入图片描述
3.根据新手指南完成 注册账号,选择角色,应用创建,这三个步骤
在这里插入图片描述
注册完之后,点击下图个人中心,就可以找到选择角色的【资质信息】模块
在这里插入图片描述
完成选择角色后,可以点击控制台,去创建应用
在这里插入图片描述
在这里插入图片描述
我这里是选择的跨境,因为我们这边的业务需求,但是这个电子面单的实现方式是一样的, 所以这个你可以按你们自己的来 只要包含电子面单打印功能即可。
在这里插入图片描述
创建完应用之后 就可以 下载相关的sdk了
在这里插入图片描述
在这里插入图片描述
点击下载即可
在这里插入图片描述
下载下来解压,它包含两部分 如图
在这里插入图片描述
可以直接把jar放在自己项目的配置文件下面
在这里插入图片描述
我这边是springboot项目 使用方法 如下:
在启动类的pom文件中添加 如图插件
在这里插入图片描述
再在需要用到jar包提供的代码的模块里加入 改jar包 并在此pom文件中加入如下 :
在这里插入图片描述
这样便可以 使用jar文件里的内容了。

完成这里之后,就去注册一个商家账号,在后续开发流程中有使用
商家后台地址:商家后台地址
注册完之后完成如下图操作 :在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

4.完成后,可以进入开发阶段
首先,找到文档,先看完相关功能 如图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
我这边没有直接按文档来 因为他又提供sdk 所以参数不需要自己封装 所以我是直接先用它提供的代码把数据组装起来 然后再来看自己 哪些参数不清楚 少哪些参数的 这里我就直接把我的获取面单代码贴出来把

//获取面单
		private   String getPDDMailNo() {
		//拼多多开放平台上申请的应用的 clientId
				String clientId="clientId";
				//拼多多开放平台上申请的应用的 clientSecret
				String clientSecret="clientSecret";
				String expresscode="YUNDA";//要获取的运单类型
					//商铺账号  可以在商家后台看到 这是拼多多店铺账号
				Long userId=0L;
				String accessToken="accessToken";//accessToken
				String code="code";//授权码
				PopClient client = new PopHttpClient(clientId, clientSecret);
				PddWaybillGetRequest request = new PddWaybillGetRequest();
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequest paramWaybillCloudPrintApplyNewRequest = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequest();
				paramWaybillCloudPrintApplyNewRequest.setNeedEncrypt(false);
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestSender sender = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestSender();
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestSenderAddress address = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestSenderAddress();
				paramWaybillCloudPrintApplyNewRequest.setWpCode(expresscode);
				address.setCity("");
				address.setDetail("");
				address.setDistrict("");
				address.setProvince("");
				sender.setAddress(address);
				sender.setName("");
				sender.setMobile("");
				sender.setPhone("");

				paramWaybillCloudPrintApplyNewRequest.setSender(sender);
				List<PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItem> tradeOrderInfoDtos = new ArrayList<PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItem>();

				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItem item = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItem();
				//建议用订单编号
				item.setObjectId("");
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemOrderInfo orderInfo = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemOrderInfo();
				orderInfo.setOrderChannelsType("PDD");
				List<String> tradeOrderList = new ArrayList<String>();
				tradeOrderList.add("");
				orderInfo.setTradeOrderList(tradeOrderList);
				item.setOrderInfo(orderInfo);
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemPackageInfo packageInfo = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemPackageInfo();
				packageInfo.setId("");
				List<PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemPackageInfoItemsItem> items = new ArrayList<PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemPackageInfoItemsItem>();
				//for () {
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemPackageInfoItemsItem item1 = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemPackageInfoItemsItem();
				item1.setCount(0);
				item1.setName("");
				items.add(item1);
				//}
				packageInfo.setItems(items);
				packageInfo.setTotalPackagesCount(0);
				packageInfo.setVolume(0L);
				packageInfo.setWeight(0L);
				item.setPackageInfo(packageInfo);
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemRecipient recipient = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemRecipient();
				PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemRecipientAddress address1 = new PddWaybillGetRequest.ParamWaybillCloudPrintApplyNewRequestTradeOrderInfoDtosItemRecipientAddress();
				address1.setCity("");
				address1.setDetail("");
				address1.setDistrict("");
				address1.setProvince("");
				address1.setTown("");
				address1.setCountry("");
				recipient.setAddress(address1);
				recipient.setMobile("");
				recipient.setName("");
				recipient.setPhone("");
				item.setRecipient(recipient);
				//运单模板
				String templateUrl=getTemplates(clientId,clientSecret,expresscode);
				item.setTemplateUrl(templateUrl);
				item.setUserId(userId);
				tradeOrderInfoDtos.add(item);
				paramWaybillCloudPrintApplyNewRequest.setTradeOrderInfoDtos(tradeOrderInfoDtos);
				request.setParamWaybillCloudPrintApplyNewRequest(paramWaybillCloudPrintApplyNewRequest);
				try {
						PddWaybillGetResponse response = client.syncInvoke(request, accessToken);
				} catch (Exception e) {
						e.printStackTrace();
				}
				return "";
		}
		//获取标准面单模板
		private   String getTemplates(String clientId,String clientSecret,String WpCode) {
				String templates="";
				PopClient client = new PopHttpClient(clientId, clientSecret);
				PddCloudprintStdtemplatesGetRequest request = new PddCloudprintStdtemplatesGetRequest();
				request.setWpCode(WpCode);
				PddCloudprintStdtemplatesGetResponse response = null;
				try {
						response = client.syncInvoke(request);
				} catch (Exception e) {
						e.printStackTrace();
				}
				//标准面单模板url
				if( response.getPddCloudprintStdtemplatesGetResponse()!=null){
						templates=response.getPddCloudprintStdtemplatesGetResponse().getResult().getDatas().get(0).getStandardTemplates().get(0).getStandardTemplateUrl();
				}
				return templates;
		}
		//获取token
		public  void getAccessToken() {
				String clientId="clientId";
				String clientSecret="clientSecret";
				String code = "code";
				String accessToken = "";
				PddPopAuthTokenCreateRequest request = new PddPopAuthTokenCreateRequest();
				request.setCode(code);
				PddPopAuthTokenCreateResponse response = null;
				PopClient client = new PopHttpClient(clientId, clientSecret);
				try {
						response = client.syncInvoke(request);
				} catch (Exception e) {
						e.printStackTrace();
				}
				if (response.getPopAuthTokenCreateResponse().getAccessToken() != null) {
						accessToken = response.getPopAuthTokenCreateResponse().getAccessToken();
				}
		}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117

接下来就说一下主要参数 从哪找 clientId,clientSecret
在这里插入图片描述
code 根据下图位置 看文档 自己拼接
拼接规则:
https://{授权页链接}?response_type=code&client_id={应用client_id}&redirect_uri={client_id对应的回调地址}&state={自定义参数}

我的是这样的 假如我的client_id=1111 回调地址=http://123 (回调地址上图可见)
https://fuwu.pinduoduo.com/service-market/auth?response_type=code&client_id=1111&redirect_uri=http://123&state=1212
在这里插入图片描述
在获取code之前需要在这里 授权店铺 点击添加 然后输入商家后台 注册时的账号名即可
在这里插入图片描述

把拼接好的地址在浏览器上打开 出现如下页面 点击授权即可
在这里插入图片描述
授权后出现的页面则是 回调地址 的网址页面 code 会在连接后
在这里插入图片描述
需要注意的时 code 10分钟过期一次 accessToken 24小时过期一次

在参数中还有一个 就是 template_url 模板url
这个参数 我上面代码有提供
按以上步骤来 就可以获取到面单号了 记得 物流审核完之后 让对应网点给点测试单

接下来就是面单打印了
文档地址:拼多多面单打印文档地址
在这里插入图片描述
打印命令数据封装
在这里插入图片描述
代码:

//拼接打印信息
				public  String  getText() {
				String clientId="clientId";
				String userId="userId";
				String uuid = UUID.randomUUID().toString().replaceAll("-", "");
				String printdata ="获取电子面单时返回的参数";
				JSONObject object = JSONObject.parseObject(printdata);
				JSONObject text = new JSONObject();
				text.put("ERPId",clientId);
				text.put("cmd", "print");
				text.put("requestID", uuid);
				JSONObject task = new JSONObject();
				com.alibaba.fastjson.JSONArray documents = new com.alibaba.fastjson.JSONArray();
				JSONObject document = new JSONObject();
				com.alibaba.fastjson.JSONArray contents = new com.alibaba.fastjson.JSONArray();
				JSONObject content = new JSONObject();
				JSONObject addData = new JSONObject();
				JSONObject sender = new JSONObject();
				JSONObject address = new JSONObject();

                //面单上是默认隐藏发件人信息   如果要显示的话 就在一面address 中加入即可  这
				address.put("city", "");
				address.put("detail", "");
				address.put("district", "");
				address.put("province", "");
				sender.put("address", address);
				sender.put("mobile", "");
				sender.put("name", "");
				addData.put("sender", sender);
				//到这

				content.put("addData", addData);
				content.put("encryptedData", object.get("encryptedData"));
				content.put("signature", object.get("signature"));
				content.put("templateUrl", object.get("templateUrl"));
				content.put("userid", userId);
				content.put("ver", object.get("ver"));
				contents.add(content);
				JSONObject content1 = new JSONObject();
				JSONObject data = new JSONObject();
				data.put("height", "");
				com.alibaba.fastjson.JSONArray lists = new com.alibaba.fastjson.JSONArray();

				//这可不填 这
				JSONObject list = new JSONObject();
				list.put("fontSize", "");
				list.put("height", "");
				list.put("left", "");
				list.put("text", "");
				list.put("top", "");
				list.put("width", "");
				lists.add(list);
				data.put("list", lists);
				JSONObject waterdata = new JSONObject();
				waterdata.put("text", "");
				data.put(
			

免费ERP

61ebf17978942.jpg

 注册    登录 

用户名: demo; 密码: 123456

联系站长

QQ:769220720

Copyright © SibooSoft All right reserved 津ICP备19011444号