您的位置 首页 php

php实现三方支付的方法有哪些?

支付模块是各个公司中公司和用户之间的交易桥梁,构建一套易用,安全,便捷的支付环境是每个公司的首要任务。在上一家公司我负责搭建该功能模块,在此对在做支付模块需要准备的资料、遇到的问题和以后规划的设想在这里做一个简单的记录。希望可以帮助到那些对支付模块刚刚接触的新人。

本文主要是两种支付方式:支付宝、微信支付,更多支付方式请自行解决,大致的流程应该都是可以通用的

资料准备

需要特殊说明的是:

微信在微信APP内部和微信外部(浏览器端H5调用支付)调用的支付方式是不一样的,需要自己仔细阅读文档,并且微信的技术客服支持不是很好,有可能都联系不到技术客服。

支付宝相对于微信就简单许多了,在支付宝APP内部和外部调用的方式是一样的,如果需要技术客服的支付,点击支付宝商户平台页面右边的机器人之后恢复任意话术7次可唤醒人工支持。

微信

注意事项

微信支付一定要仔细看文档,微信技术客服不好找。

微信公众号支付,吊起支付的页面是前端做的

支付准备

申请开通微信公众账号、开通微信商户平台、开通微信开放平台

简要说明一下这三者的关系:

微信公众账号:支付功能需要使用开通服务号并开通微信公众账号支付。微信APP内部支付就是走的微信公众号支付。

微信商户平台:这个可以看字面意思就是商户平台,你的交易记录都可以查询到,并且要实现微信公众账号支付的话,微信公众账号需要和该平台做关联。

微信开放平台:这个和支付宝没什么关系,拿到这里来说是因为他是关于微信的,他的主要功能:如果一个公司有多个微信公众账号运营的话,并且每个微信公众号都可以拉取用户信息的话,将该用户记录到我们的用户库里面,就需要将公司所有的微信公众账号和此平台绑定。绑定后用户无论访问哪一个微信公众账号,在调用微信接口获取用户信息的时候,都能获取到用户相对于我们的平台产生的唯一的unionid。该unionid的说明详细参照微信公众号开发文档。

支付功能

微信公众号支付:

使用场景:微信内部的H5支付/PC微信扫码支付

文档地址:

申请开通微信支付文档

微信公众号支付文档

微信支付异步支付通知接口地址

支付流程说明:

通过微信公众号微信网页授权接口获取用户微信openid

调用微信商户平台统一下单接口创建订单信息

在微信内部支付页唤起支付宝

微信wap(H5)支付:

使用场景:移动端浏览器支付

特别声明:H5支付目前需要单独申请(如果文档有则可以直接接入,没有则联系微信客服问问)

文档地址:

微信H5支付接口文档地址

微信支付异步支付通知接口地址

支付流程说明:

用微信商户平台统一下单接口创建订单信息 ,返回mweb_url

浏览器端直接跳转到 mweb_url

微信APP支付:

使用场景:安卓APP端微信支付

文档地址:

支付文档

支付流程说明:

安卓端下载并配置相应的SDK

调用统一下单接口

异步回调

支付宝

支付准备

申请开通蚂蚁金服开放平台

支付功能

手机网站支付(wap支付)

使用场景:PC扫码支付、H5端支付

文档地址:

支付宝手机网站支付文档

支付异步通知

支付流程:

吊起支付

支付宝APP支付

使用场景:安卓端所有的APP

支付文档:

APP支付文档

支付流程:

Android集成流程

目前的架构

采用传统的架构模式,采用模块的方式开发,一个模块处理了支付相关的所有东西。

优点:

前期开发周期快

需要的开发人员少

调试方便

缺点:

项目到后期需要加个性化的东西,牵一发而动全身

维护麻烦

公司新人接入周期长

预想的架构(未实现)

支付宝和微信支付都有异步回调通知,我的想法是将支付模块拆分成多个模块,大概的拆分逻辑:

支付模块

微信支付模块

支付宝支付模块

异步通知账单处理模块

基本的实现步骤是:

支付模块生成支付订单,将订单存入到redis中,生成唯一Key,作为公司层面的订单号。在生成统一下单时候将该订单号传入进去。异步通知时候提交到我们的服务端。

服务端接收到异步通知中的订单号,对接受的参数做合法验证之后,可以直接告诉前段,该用户已经支付完成。订单的写入使用异步处理。

优点:

模块清晰,容易上手

维护简单,比如调整了微信支付,只验证微信支付即可。

新手接入速度快。

缺点:

维护成本较高(时间成本和人力成本)

数据同步逻辑复杂。

模块较多,运维成本较高

具体代码实现

PC 一个二维码支持多平台扫码支付

该方式的实现逻辑主要如下:

ajax请求服务端接口,服务端将生成唯一订单号和扫码跳转链接绑定到二维码上,返回给前端一个二维码链接;

用户使用手段APP扫描二维码,请求到绑定的二维码跳转链接上,该方法中对请求端的useragent做判断,看看是什么APP做的支付请求:

function IsUa(){

$userAgent = $_SERVER[‘HTTP_USER_AGENT’];

// $str 名称和相应的支付控制器要对应

switch ($userAgent) {

case ( strpos( $userAgent, ‘MicroMessenger’ ) !== false ):

$str = ‘wxpay’; //微信支付

break;

case ( strpos( $userAgent, ‘AlipayClient’ ) !== false ):

$str = ‘alipay’; //支付宝支付

break;

default:

$str = ‘other’;

}

return $str;

}

根据不同的useragent做不同的支付处理创建。

用户支付完成,第三方支付调用我们在第一步调用 统一下单接口中的【notify_url】往我们的服务端推送支付消息。

对推送过来的消息做校验,校验完成写入数据库并通知前段提示支付成功。

其他段的支付都大同小异,调用统一下单,用户支付完成,异步订单处理。

文章来源:智云一二三科技

文章标题:php实现三方支付的方法有哪些?

文章地址:https://www.zhihuclub.com/79254.shtml

关于作者: 智云科技

热门文章

评论已关闭

31条评论

  1. Only three patients approximately 4 had no normal alleles homozygous vt vt and this corresponds to expected population frequencies reported greater than 5 to 10

  2. Abnormal per vaginal discharge, especially if blood tinged, may be the only sign of endometrial complex and atypical hyperplasia, and cancer, and it should be noted and the cause pursued even during the reproductive years, especially during the fourth and fifth decades of life, and after menopause

  3. Disruption of Trp53 in livers of mice induces formation of carcinomas with bilineal differentiation They were stunned to find a hovel Гў a single room basement apartment with no bathroom

  4. For the best up to date information relating to Preston and the surrounding areas visit us at Lancashire Evening Post regularly or bookmark this page

  5. The key to obtaining the most bang for your buck is understanding the Oxandrolone hormone, knowing what it can do and implementing it into your plan for the right purpose Starting Your Application

  6. 171 C 500 mg Disp Investigators examined outcomes in women treated with hormonal maintenance compared with observation after primary cytoreductive surgery and platinum based chemotherapy in women with stage II to IV disease

  7. Quality of care is important to every oncology professional All ER cDNAs were cloned into the pSG5 vector under the simian virus 40 promoter Rosenauer et al

  8. The chances of co administration of tamoxifen and red clover are very likely in breast cancer and postmenopausal women

  9. I have had the worst pelvic pain starting yesterday Sun and today Mon and I am not sure if it is from the Clomid or if something else is going on in there

  10. The primary causes of POR remain elusive and oxidative stress was proposed as one of the important contributors

  11. Interestingly, although metformin is frequently referred to as a calorie restriction mimetic, few attempts have been made to make a direct comparison of these two interventions

  12. Participants reflected on the unfairness of their situation as they have the means or the desire to have a child, but are denied this prerogative, whilst other women who, in their opinion should not have children are fortunate enough to be blessed with children As he moved southflaortho

  13. Immature Not able to be used for ICSI unless becomes mature within 2 hours When recurrent cancer is confirmed, the physician orders blood tests and a bone scan to determine whether the cancer has spread beyond the breast

  14. Bishof chose to keep her son home last year but her district will be changing its remote learning program this year

  15. Metformin was child s play, only gave me running stomach Safety of Lifitegrast Ophthalmic Solution 5

  16. As other anti pseudomonal antibiotics were concomitantly utilized in many patients in the clinical trials, the association with TOBI Podhaler is not clear

  17. MG Cytochrome P450 enzymes are involved in the metabolism of both exogenous and endogenous compounds We would all agree that hearing aids are an absolutely necessary measure to take in most instances of hearing loss

  18. Nevertheless, a trend towards a decrease in seizure frequency and increase in responder rate during levetiracetam administration compared to placebo warrants further evaluation in a larger scale study Absence of tetrahydrofolate reduces DNA synthesis and induces cell death

  19. Trials performed in patients undergoing kidney transplantation suggest that IFTA is strongly implicated with graft failure, progression, and increased mortality 12, 13, 14

网站地图