极乐门资源网 Design By www.ioogu.com
本文实例讲述了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程序设计有所帮助。
标签:
python,京东订单,推送
极乐门资源网 Design By www.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无python实现京东订单推送到测试环境,提供便利操作示例的评论...
更新日志
2024年09月20日
2024年09月20日
- 黑神话悟空上品鼠弩手精魄获取方法一览|上品鼠弩手精魄收集攻略
- 中国音乐地图听见世界非物质文化遗产《非遗HQCD》wav
- 中国民乐合奏作品集《华夏之音HQ》头版限量编号[WAV+CUE]
- [电影原声带]黎允文《天将雄师》[FLAC+CUE]
- 曝NS继任机型已进入量产阶段:已花了30亿日元
- 不是Switch2?曝《马里奥惊奇》NS捆绑包即将公开
- 暖心任天堂!网友Switch维修返还时贴纸被完好保留
- 《国语老歌 经典对唱情歌 2CD》[WAV/分轨][1.1GB]
- 《刀郎 翻唱精选华语专辑 披着羊皮的狼 》[WAV+CUE][430MB]
- 《真的田震 中国乐坛红极一时的歌者 精品集》[WAV+CUE][300MB]
- 群星.1995-新滚石九大天王之情歌大全【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·纵夏欢唱【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·贺岁齐唱【滚石】【WAV+CUE】
- 黑神话悟空上品虫校尉精魄获取方法一览|上品虫校尉精魄收集攻略
- 《指环王:夏尔的传说》推迟至2025年初发行