菜鸟电子面单获取教程


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;

namespace FormTest
{
    public partial class Form1 : Form
    {
//以下四个值是在菜鸟开通电子面单服务后得到
        string serverUrl = "xxxx";
        string appKey = "xxxx";
        string appSecret = "xxxx";
        string sessionKey = "xxxx";

        List<string> tradeOrderList;

        public Form1()
        {
            InitializeComponent();
        }

//测试
        private void button1_Click(object sender, EventArgs e)
        {
            //第一步 获取到用户ID,
            //对应接口: taobao.user.seller.get (查询卖家用户信息)
            long UserID = UserSellerGet(); 
            //第二步 获取到发件人信息(取快递单必须用这个地址设置),
            //对应接口: cainiao.waybill.ii.search (查询面单服务订购及面单使用情况)
            CainiaoWaybillIiSearchResponse SenderInfo = WaybillIiSearch();
            //第三部 获取快递单号
            //对应接口: cainiao.waybill.ii.get (电子面单云打印接口)
            GetWaybill(SenderInfo, UserID);
        }

        //获取UserID
        public long UserSellerGet()
        {
            ITopClient client = new DefaultTopClient(serverUrl, appKey, appSecret);
            UserSellerGetRequest req = new UserSellerGetRequest();
            req.Fields = "user_id,nick,sex";
            UserSellerGetResponse rsp = client.Execute(req, sessionKey);
            long UserID = rsp.User.UserId;
            Console.WriteLine(rsp.Body);
            return UserID;
        }

        //查询商家电子面单开通信息, 主要是为了去地址信息
        public CainiaoWaybillIiSearchResponse WaybillIiSearch()
        {
            ITopClient client = new DefaultTopClient(serverUrl, appKey, appSecret);
            CainiaoWaybillIiSearchRequest req = new CainiaoWaybillIiSearchRequest();
            //req.CpCode = "YUNDA";
            CainiaoWaybillIiSearchResponse rsp = client.Execute(req, sessionKey);
            Console.WriteLine(rsp.Body);
            return rsp;
        }

        //获取面单号
        public void GetWaybill(CainiaoWaybillIiSearchResponse SenderInfo, long UserID)
        {
            ITopClient client = new DefaultTopClient(serverUrl, appKey, appSecret);
            CainiaoWaybillIiGetRequest req = new CainiaoWaybillIiGetRequest();
            CainiaoWaybillIiGetRequest.WaybillCloudPrintApplyNewRequestDomain obj1 = new CainiaoWaybillIiGetRequest.WaybillCloudPrintApplyNewRequestDomain();
            obj1.CpCode = "YUNDA";
            //obj1.ProductCode = "";
            CainiaoWaybillIiGetRequest.UserInfoDtoDomain obj2 = new CainiaoWaybillIiGetRequest.UserInfoDtoDomain();
            CainiaoWaybillIiGetRequest.AddressDtoDomain obj3 = new CainiaoWaybillIiGetRequest.AddressDtoDomain();
            obj3.City = "xx从SenderInfo中获取xx";
            obj3.Detail = "xx从SenderInfo中获取xx";
            obj3.District = "xx从SenderInfo中获取xx";
            obj3.Province = "xx从SenderInfo中获取xx;
            obj3.Town = "";
            obj2.Address = obj3;
            obj2.Mobile = "xxxxxx";
            obj2.Name = "xxxx";
            obj2.Phone = "";
            obj1.Sender = obj2;
            List<CainiaoWaybillIiGetRequest.TradeOrderInfoDtoDomain> list5 = new List<CainiaoWaybillIiGetRequest.TradeOrderInfoDtoDomain>();
            CainiaoWaybillIiGetRequest.TradeOrderInfoDtoDomain obj6 = new CainiaoWaybillIiGetRequest.TradeOrderInfoDtoDomain();
            list5.Add(obj6);
            obj6.LogisticsServices = "";
            obj6.ObjectId = UserID + "";   // 商家的UserID
            CainiaoWaybillIiGetRequest.OrderInfoDtoDomain obj7 = new CainiaoWaybillIiGetRequest.OrderInfoDtoDomain();
            obj7.OrderChannelsType = "TB";

            tradeOrderList = new List<string>();
            tradeOrderList.Add("PU1710121-001");
            obj7.TradeOrderList = tradeOrderList;
            obj6.OrderInfo = obj7;
            CainiaoWaybillIiGetRequest.PackageInfoDtoDomain obj8 = new CainiaoWaybillIiGetRequest.PackageInfoDtoDomain();
            obj8.Id = "1";
            List<CainiaoWaybillIiGetRequest.ItemDomain> list10 = new List<CainiaoWaybillIiGetRequest.ItemDomain>();
            CainiaoWaybillIiGetRequest.ItemDomain obj11 = new CainiaoWaybillIiGetRequest.ItemDomain();
            list10.Add(obj11);
            obj11.Count = 1L;
            obj11.Name = "衣服";
            obj8.Items = list10;
            obj8.Volume = 1L;
            obj8.Weight = 1L;
            obj6.PackageInfo = obj8;
            CainiaoWaybillIiGetRequest.UserInfoDtoDomain obj12 = new CainiaoWaybillIiGetRequest.UserInfoDtoDomain();
            CainiaoWaybillIiGetRequest.AddressDtoDomain obj13 = new CainiaoWaybillIiGetRequest.AddressDtoDomain();
            obj13.City = "xxxxxx市";
            obj13.Detail = "测试详细地址";
            obj13.District = "xx区";
            obj13.Province = "xxxxxxxxx";
            obj13.Town = "";
            obj12.Address = obj13;
            obj12.Mobile = "xxxxxxxxx";
            obj12.Name = "xxxxxxxxxxxx";
            obj12.Phone = "xxxxxxxxx";
            obj6.Recipient = obj12;
            obj6.TemplateUrl = "http://cloudprint.cainiao.com/cloudprint/template/getStandardTemplate.json?template_id=1001";
            obj6.UserId = 12L;
            obj1.TradeOrderInfoDtos = list5;
            obj1.StoreCode = "";
            obj1.ResourceCode = "DISTRIBUTOR_978324";
            obj1.DmsSorting = false;
            req.ParamWaybillCloudPrintApplyNewRequest_ = obj1;
            CainiaoWaybillIiGetResponse rsp = client.Execute(req, sessionKey);
            Console.WriteLine(rsp.Body);

            string WaybillCode = rsp.Modules[0].WaybillCode;
        }

    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值