阿里的支付也就是支付宝,官网以及出了Python的SDK了~所以要先下载~~
pip install alipay-sdk-python支付宝沙箱环境的地址 href="https://openhome.alipay.com/platform/appDaily.htm?tab=info" target="_blank">https://openhome.alipay.com/platform/appDaily.htm?tab=info
注意:
如果安装alipay报
需要先下载一个安装环境:
pip install alipay-sdk-python具体 *** 作第一步 访问沙箱环境地址,注册一个商家账户按照他要求的方式生成商户的公钥和私钥~把公钥放入网站~私钥自己留着签名用~~
下面是商户信息以及卖家信息~下载一个支付宝的沙箱环境~
然后按照下面的账号和密码登录和支付~~只支持安卓的~
第二步 阅读文档 找到一个适合自己的API仔细阅读文档~按照文档的参数要求去向接口发请求~~
第三步 代码实例 django.conf.urls django.contrib demo.vIEws urlpatterns =<span > [url(r<span >'<span >^admin/<span >'<span >,admin.site.urls),url(r<span >'<span >^pay$<span >'<span >,AliPayVIEw.as_vIEw()),url(r<span >'<span >^alipay_handler<span >'<span >,PayHandlerVIEw.as_vIEw()),] django.shortcuts django.http rest_framework.vIEws rest_framework.response alipay.aop.API.DefaultAlipayClIEnt alipay.aop.API.AlipayClIEntConfig alipay.aop.API.domain.AlipayTradePrecreateModel alipay.aop.API.request. AlipayTradePrecreateRequest alipay.aop.API.domain.AlipayTradePagePayModel alipay.aop.API.request.AlipayTradePagePayRequest <span >#<span > Create your vIEws here.<span ><span > 沙箱环境地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info
<span >#
<span > "https://openAPI.alipaydev.com/gateway.do",APP_ID,APP_PRIVATE_KEY,"Json",CHARSET,AliPAY_PUBliC_KEY,"RSA2"<span >def
<span > ali_pay():<span >#<span > 为阿里支付实例化一个配置信息对象
alipay_config = AlipayClIEntConfig(sandBox_deBUG=<span >True)
<span >#<span > 初始化各种配置信息
<span >#<span > 阿里提供服务的接口
alipay_config.server_url = <span >"<span >https://openAPI.alipaydev.com/gateway.do<span >"
<span >#<span > 申请的沙箱环境的app_ID
alipay_config.app_ID = <span >"<span >2016091800540924<span >"
<span >#<span > 商户的私钥
with open(<span >"<span >keys/app_private_key.txt<span >"<span >) as f:
alipay_config.app_private_key =<span > f.read()
<span >#<span > 阿里的公钥
with open(<span >"<span >keys/alipay_public_key.txt<span >"<span >) as f:
alipay_config.alipay_public_key =<span > f.read()
<span >#<span > 实例化一个支付对象并返回
alipay_clIEnt = DefaultAlipayClIEnt(alipay_clIEnt_config=<span >alipay_config)
<span >return<span > alipay_clIEnt
<span >class<span > AliPayVIEw(APIVIEw):
<span >def<span > get(self,request):
<span >return render(request,<span >"<span >pay.HTML<span >"<span >)
</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> <a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" >生成</a>支付宝<a href="https://www.jb51.cc/tag/zidai/" target="_blank" >自带</a><a href="https://www.jb51.cc/tag/yemian/" target="_blank" >页面</a>的<a href="https://m.jb51.cc/tag/API/" target="_blank" >API</a></span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">def</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> post(self,request): </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 得到阿里支付的实例化对象</span> cl<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>nt =<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> a<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>_pay() </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 为<a href="https://m.jb51.cc/tag/API/" target="_blank" >API</a><a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" >生成</a><a href="https://www.jb51.cc/tag/yige/" target="_blank" >一个</a><a href="https://m.jb51.cc/tag/moban/" target="_blank" >模板</a>对象 初始化<a href="https://m.jb51.cc/tag/canshu/" target="_blank" >参数</a>用的</span> model =<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> A<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>pay<a href="https://www.jb51.cc/tag/Trad/" target="_blank" >Trad</a>ePagePayModel() </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 订单号</span> model.out_<a href="https://www.jb51.cc/tag/Trad/" target="_blank" >Trad</a>e_no = <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">pay</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span> +<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> str(time.time()) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 金额</span> model.total_amount = 8888 <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 商品<a href="https://www.jb51.cc/tag/biaoti/" target="_blank" >标题</a></span> model.subject = <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">测试</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 商品详细<a href="https://www.jb51.cc/tag/neirong/" target="_blank" >内容</a></span> model.body = <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">支付宝测试</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 销售产品码,与支付宝签约的产品码<a href="https://www.jb51.cc/tag/mingcheng/" target="_blank" >名称</a></span> model.product_code = <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">FAST_INSTANT_<a href="https://www.jb51.cc/tag/Trad/" target="_blank" >Trad</a>E_PAY</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 实例化<a href="https://www.jb51.cc/tag/yige/" target="_blank" >一个</a>请求对象</span> request = A<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>pay<a href="https://www.jb51.cc/tag/Trad/" target="_blank" >Trad</a>ePagePayRequest(biz_model=<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;">model) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> get请求 <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" >用户</a>支付成功后返回的<a href="https://www.jb51.cc/tag/yemian/" target="_blank" >页面</a>请求<a href="https://m.jb51.cc/tag/dizhi/" target="_blank" >地址</a></span> request.return_url = <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;"><a href="https://m.jb51.cc/tag/http/" target="_blank" >http</a>://140.143.63.45:8000/a<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>pay_handler</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> post请求 <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" >用户</a>支付成功<a href="https://www.jb51.cc/tag/tongzhi/" target="_blank" >通知</a>商户的请求<a href="https://m.jb51.cc/tag/dizhi/" target="_blank" >地址</a></span> request.notify_url = <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;"><a href="https://m.jb51.cc/tag/http/" target="_blank" >http</a>://140.143.63.45:8000/a<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>pay_handler</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> 利用阿里支付对象发<a href="https://www.jb51.cc/tag/yige/" target="_blank" >一个</a>获得<a href="https://www.jb51.cc/tag/yemian/" target="_blank" >页面</a>的请求 <a href="https://m.jb51.cc/tag/canshu/" target="_blank" >参数</a>是request</span> response = cl<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>nt.page_execute(request,<a href="https://m.jb51.cc/tag/http/" target="_blank" >http</a>_method=<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">GET</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;">) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">return</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> redirect(response)
<span >class<span > PayHandlerVIEw(APIVIEw):
</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">def</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> get(self,request): </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> return_url的回调<a href="https://m.jb51.cc/tag/dizhi/" target="_blank" >地址</a></span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">print</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;">(request.data) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" >用户</a>支付成功之后回到哪</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">return</span> <a href="https://m.jb51.cc/tag/http/" target="_blank" >http</a>Response(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">return_url测试</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;">)</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">def</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;"> post(self,request): </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">print</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;">(request.data) </span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;">#</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #008000;"> <a href="https://www.jb51.cc/tag/yonghu/" target="_blank" >用户</a>支付成功 <a href="https://www.jb51.cc/tag/zaizheli/" target="_blank" >在这里</a><a href="https://www.jb51.cc/tag/xiugai/" target="_blank" >修改</a>订单状态<a href="https://m.jb51.cc/tag/yiji/" target="_blank" >以及</a>优惠券贝里等等情况</span> <span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #0000ff;">return</span> <a href="https://m.jb51.cc/tag/http/" target="_blank" >http</a>Response(<span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">notify_url</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #800000;">"</span><span https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #000000;">)
vIEws.py
注意: 我们的回调url的测试要放在公网IP上~所以测试的时候放入自己服务器
总结以上是内存溢出为你收集整理的调用支付宝支付接口全部内容,希望文章能够帮你解决调用支付宝支付接口所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)