日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python實現(xiàn)京東訂單推送到測試環(huán)境,提供便利操作示例

系統(tǒng) 1798 0

本文實例講述了python實現(xiàn)京東訂單推送到測試環(huán)境,提供便利操作。分享給大家供大家參考,具體如下:

            
# -*- coding: utf-8 -*-
import hashlib
import time
import requests
from order30 import conf
app_key = conf.jd_appkey
appSecret = conf.jd_secret
token = conf.jd_token
def get_md5(string):#返回字符串md5加密后大寫
  hl = hashlib.md5()
  hl.update(string.encode('utf-8'))
  return hl.hexdigest().upper()
def get_timestr():#獲取2分鐘前的時間
  time_now = int(time.time())-120
  timestr = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time_now))
  return timestr
def req_get_result(api_url,api_data):#get方法請求函數(shù)
  req_get = requests.get(api_url,api_data)
  result = req_get.json()
  return result
def req_post_result(api_url,api_data):#post方法請求函數(shù)
  req_post = requests.post(api_url,data=api_data)
  result = req_post.json()
  return result
def param_sort(param_dict):#傳入字典,返回排序后并且連接好的字符串
  keys_list = sorted(param_dict.keys())
  rb_str = ''
  for k in keys_list:
    key_value = k + str(param_dict[k])
    rb_str = rb_str + key_value
  return rb_str
def op_jd_order(outer_order_id,optype):#向測試環(huán)境推送一個訂單
  api_url_dict = {
    "33060":"http://xx.xxx.xxx.com/jd/xxx1",# 用戶確認收貨完成訂單
    "32000":"http://xx.xxx.xxx.com/jd/xxx2", #創(chuàng)建新訂單
    "10":"http://xx.xxx.xxx.com/jd/xxx3",#用戶申請售后
  }
  api_url = api_url_dict[optype]
  timestamp = get_timestr()
  jd_parms = '{"billId":"%s","statusId":"%s","timestamp":"%s"}'%(outer_order_id,optype,timestamp)
  api_data = {
  'token':token,
  'app_key':app_key,
  'timestamp':timestamp,
  'format':'json',
  'v':'1.0',
  'jd_param_json':jd_parms
  }
  sort_str = param_sort(api_data) #對參數(shù)進行排序,連接。
  params_str = appSecret + sort_str + appSecret #首尾加上appSecret
  sign = get_md5(params_str)#獲得簽名后的大寫字符串
  api_data['sign'] = sign
  req = req_post_result(api_url,api_data)
  return req


          

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對大家Python程序設計有所幫助。


更多文章、技術(shù)交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 夏津县| 新丰县| 台中市| 喀什市| 共和县| 读书| 盐城市| 方正县| 安新县| 琼海市| 牙克石市| 陆川县| 瑞丽市| 伊川县| 巴楚县| 乌拉特后旗| 六枝特区| 宁波市| 华安县| 拉萨市| 呼图壁县| 河源市| 清水河县| 盐亭县| 开封市| 竹山县| 罗平县| 报价| 玉龙| 邻水| 安顺市| 余庆县| 临沭县| 滦平县| 张家川| 宁阳县| 天津市| 九寨沟县| 云林县| 柘城县| 宜兰市|