Python调用服务接口的实例

时间:2021-05-22

如下所示:

#! /usr/bin/env python# coding=utf-8####################################################################### Author: yini.xie# Create Time: 2016-07-05 16:28:42# Descriptioin:######################################################################import osimport sysimport timeimport jsonimport urllibimport urllib2from urllib import quotefrom datetime import datetime pathATM = "http://192.168.217.217:4080/invoke.json" def fmtLen(value, length=7): fmt = '{0:>%d}' % (length) return fmt.format(value) def changeWithdrawRule(customerId, productCode, ruleTemplateId, ruleId, operator): service_url_s = "http://service.xxx.com/tsService/TSRuleService_1.0.0" method_s = "bindCustomerWithdrawRuleTemplate" params_s = "parameters[]=%d&parameters[]=%d&parameters[]=%d&parameters[]=%d&parameters[]=%s" % (customerId, productCode, ruleTemplateId, ruleId, operator) params_s += "&url=%s&method=%s&parameterTypes[]=int&parameterTypes[]=int&parameterTypes[]=int&parameterTypes[]=int&parameterTypes[]=java.lang.String" % (service_url_s, method_s) url_s = pathATM + "?" + quote(params_s, safe='&=') data_s = urllib2.urlopen(url_s).read() print url_s return json.loads(data_s) if __name__ == '__main__': start = datetime.now() for line in open(sys.argv[1]).xreadlines(): fields = line.strip().split() customerId = int(fields[0]) productCode = int(fields[1]) ruleTemplateId = int(fields[2]) ruleId = int(fields[3]) print "start to deal customerId = " + str(customerId) changeWithdrawRule(customerId, productCode, ruleTemplateId, ruleId, "Case") end = datetime.now()

运行Python脚本,即可调用相应的接口修改数据库数据。

python ChangeCustomerRule.py text.txt

text.txt中即为参数,以空格分隔

以上这篇Python调用服务接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章