基于Python的中国平安保险api调用代码实例.doc
文本预览下载声明
基于Python的中国平安保险api调用代码实例
代码描述:基于Python的中国平安保险api调用代码实例
代码平台:聚合数据
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, urllib
from urllib import urlencode
?
#----------------------------------
# 免费出行保险调用示例代码 - 聚合数据
# 在线接口文档:/docs/179
#----------------------------------
?
def main():
?
????#配置您申请的APPKey
????appkey = *********************
?
????#1.提交信息,获取验证码
????request1(appkey,GET)
?
????#2.获取车辆赠险
????request2(appkey,GET)
?
?
?
#提交信息,获取验证码
def request1(appkey, m=GET):
????url = /carInsuranceGift/check
????params = {
????????key : appkey, #您申请的appKey
????????mobile : , #申请人的手机号,用来接收验证码和保险单号
????????company : , #应用名,公司名或者网站名称 短信模板:【company】您的验证码是#code#.如非本人操作,请忽略本短信
????????realname : , #姓名
????????gender : , #性别?? M:男,F:女
????????birth : , #生日 格式如: 1988-01-01
????????product : , #保险产品代码,JSWY:驾驶员意外险,WYCX:公共交通意外险,SEWYCX:少儿公共交通意外险
????????idcard : , #身份证号
????????city : , #城市名,如: 上海
????????carmodel : , #车型
?
????}
????params = urlencode(params)
????if m ==GET:
????????f = urllib.urlopen(%s?%s % (url, params))
????else:
????????f = urllib.urlopen(url, params)
?
????content = f.read()
????res = json.loads(content)
????if res:
????????error_code = res[error_code]
????????if error_code == 0:
????????????#成功请求
????????????print res[result]
????????else:
????????????print %s:%s % (res[error_code],res[reason])
????else:
????????print request api error
?
#获取车辆赠险
def request2(appkey, m=GET):
????url = /carInsuranceGift/gift
????params = {
????????key : appkey, #您申请的appKey
????????mobile : , #手机号 申请成功后将作为接收保险单号的手机号码
????????verification : , #验证码
?
????}
????params = urlencode(params)
????if m ==GET:
????????f = urllib.urlopen(%s?%s % (url, params))
????else:
????????f = urllib.urlopen(url, params)
?
????content = f.read()
????res = json.loads(content)
????if res:
????????error_code = res[error_code]
????????if error_code == 0:
????????????#成功请求
????????????print res[result]
????????else:
????????????print %s:%s % (res[error_code],res[reason])
????else:
????????print request api
显示全部