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

python實現京東訂單推送到測試環境,提供便利操作示例

系統 1695 0

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

            
# -*- 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方法請求函數
  req_get = requests.get(api_url,api_data)
  result = req_get.json()
  return result
def req_post_result(api_url,api_data):#post方法請求函數
  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):#向測試環境推送一個訂單
  api_url_dict = {
    "33060":"http://xx.xxx.xxx.com/jd/xxx1",# 用戶確認收貨完成訂單
    "32000":"http://xx.xxx.xxx.com/jd/xxx2", #創建新訂單
    "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) #對參數進行排序,連接。
  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


          

更多關于Python相關內容可查看本站專題:《Python Socket編程技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》

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


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 大悟县| 清水河县| 土默特右旗| 安平县| 阳新县| 革吉县| 平顺县| 胶南市| 瑞丽市| 资阳市| 济南市| 宝清县| 东乌| 深圳市| 枝江市| 克山县| 河北省| 灌阳县| 阳城县| 凤翔县| 固阳县| 四会市| 鄂托克前旗| 桦川县| 淳化县| 永善县| 闻喜县| 建德市| 湛江市| 开远市| 景东| 台北县| 通道| 乐都县| 运城市| 河源市| 吉林省| 垣曲县| 临沂市| 正阳县| 杭州市|