基于Python的中国平安保险api调用代码实例

2022-07-11 21:18:17   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《基于Python的中国平安保险api调用代码实例》,欢迎阅读!
平安保险,中国,调用,实例,基于

基于Python的中国平安保险api调用代码实例

代码描述:基于Python的中国平安保险api调用代码实例 代码平台:聚合数据



#!/usr/bin/python

# -*- coding: utf-8 -*- import json, urllib

from urllib import urlencode



#----------------------------------

# 免费出行保险调用示例代码 聚合数据

# 在线接口文档:http://www.juhe.cn/docs/179 #----------------------------------



def main():



#配置您申请的APPKey

appkey = "*********************"



#1.提交信息,获取验证码 request1(appkey,"GET")



#2.获取车辆赠险

request2(appkey,"GET")



#提交信息,获取验证码

def request1(appkey, m="GET"):

url = "http://japi.juhe.cn/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 = "http://japi.juhe.cn/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 error"



if __name__ == '__main__': main()


本文来源:https://www.dywdw.cn/a2eb9c53fd0a79563d1e7215.html

相关推荐
推荐阅读