コード例 #1
0
        public string execute(ZopRequest request)
        {
            string url = request.url;
            NameValueCollection requestParams = request.requestParams;
            int           i = 0;
            StringBuilder queryStringBuilder = new StringBuilder();
            StringBuilder digeStringBuilder  = new StringBuilder();

            foreach (string key in requestParams.Keys)
            {
                if (i > 0)
                {
                    queryStringBuilder.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(requestParams[key], Encoding.UTF8));
                    digeStringBuilder.AppendFormat("&{0}={1}", key, requestParams[key]);
                }
                else
                {
                    queryStringBuilder.AppendFormat("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(requestParams[key], Encoding.UTF8));
                    digeStringBuilder.AppendFormat("{0}={1}", key, requestParams[key]);
                }
                i++;
            }

            NameValueCollection headers = new NameValueCollection();

            headers.Add("x-companyid", properties.companyid);
            string strToDigest = digeStringBuilder + properties.key;

            headers.Add("x-datadigest", EncryptMD5Base64(strToDigest));
            return(HttpUtil.post(url, headers, queryStringBuilder.ToString(), request.timeout));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // 这里的ZopProperties的构造方法的两个参数companyid和key,请到个人中心查看
            ZopProperties properties = new ZopProperties("appKey", "appSecret");
            ZopClient     client     = new ZopClient(properties);
            ZopRequest    request    = new ZopRequest();

            request.url = "提供的url地址";
            // addParam函数添加的是业务参数,每个接口的业务参数都不同,请查看API对应的文档描述
            // 示例中的这个api只有一个名为data的业务参数
            request.addParam("data", "{\"content\":{\"branchId\":\"\",\"buyer\":\"\",\"collectMoneytype\":\"CNY\",\"collectSum\":\"12.00\",\"freight\":\"10.00\",\"id\":\"xfs2018031500002222333\",\"orderSum\":\"0.00\",\"orderType\":\"1\",\"otherCharges\":\"0.00\",\"packCharges\":\"1.00\",\"premium\":\"0.50\",\"price\":\"126.50\",\"quantity\":\"2\",\"receiver\":{\"address\":\"育德路XXX号\",\"area\":\"501022\",\"city\":\"四川省,XXX,XXXX\",\"company\":\"XXXX有限公司\",\"email\":\"[email protected]\",\"id\":\"130520142097\",\"im\":\"yangyijia-abc\",\"mobile\":\"136*****321\",\"name\":\"XXX\",\"phone\":\"010-222***89\",\"zipCode\":\"610012\"},\"remark\":\"请勿摔货\",\"seller\":\"\",\"sender\":{\"address\":\"华新镇华志路XXX号\",\"area\":\"310118\",\"city\":\"上海,上海市,青浦区\",\"company\":\"XXXXX有限公司\",\"email\":\"[email protected]\",\"endTime\":1369033200000,\"id\":\"131*****010\",\"im\":\"1924656234\",\"mobile\":\"1391***5678\",\"name\":\"XXX\",\"phone\":\"021-87***321\",\"startTime\":1369022400000,\"zipCode\":\"610012\"},\"size\":\"12,23,11\",\"tradeId\":\"2701843\",\"type\":\"1\",\"typeId\":\"\",\"weight\":\"0.753\"},\"datetime\":\"2018-3-30 12:00:00\",\"partner\":\"test\",\"verify\":\"ZTO123\"}");
            Console.WriteLine(client.execute(request));
        }