Python调用服务接口

#! /usr/bin/env python
# coding=utf-8
######################################################################
# Author: yini.xie
# Create Time: 2016-07-05 16:28:42
# Descriptioin:
######################################################################
import os
import sys
import time
import json
import urllib
import urllib2
from urllib import quote
from 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中即为参数,以空格分隔

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值