摘要:这篇文章主要介绍了PHP 接入支付宝即时到账功能。首先请到支付宝那边申请一个及时到账的接口账户,需要提交相关材料申请。然后根据即时到账的API文档进行接入。API文档提供了各种语言版本的demo,我这里是下的php版demo,然后再进行相关修改操作。你也可以将demo版本的代码重新整合,我这里暂时为了走通充值及时到账流程,就不进行代码重构了。前台表单提交<form action=&
这篇文章主要介绍了PHP 接入支付宝即时到账功能。
首先请到支付宝那边申请一个及时到账的接口账户,需要提交相关材料申请。然后根据即时到账的API文档进行接入。API文档提供了各种语言版本的demo,我这里是下的php版demo,然后再进行相关修改操作。你也可以将demo版本的代码重新整合,我这里暂时为了走通充值及时到账流程,就不进行代码重构了。
前台表单提交
<form action="/pay/alipayapi.php" class="tm-panel-small uk-form uk-form-stacked" method="post" target="_blank"> <div class="element" style="margin-top:60px;"> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">订单序号:</label> <input class="uk-form-width-large" type="text" name="WIDout_trade_no" id="out_trade_no" value="<?php echo trim($_GET['orderid']);?>" > <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">商品名称:</label> <input class="uk-form-width-large" type="text" name="WIDsubject" value="<?php echo trim($_GET['orderid']);?>" > <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">付款金额:</label> <input class="uk-form-width-large" type="text" name="WIDtotal_fee" value="<?php echo trim($_GET['amt']);?>"> <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">商品描述:</label> <input class="uk-form-width-large" type="text" name="WIDbody" value="订单测试支付"> <br> </div> </div> <input type="hidden" name="uid" value="<?php echo $_GET['uid'];?>"> <input type="hidden" name="codes" value="<?php echo $_GET['code'];?>"> <input type="hidden" name="tags" value="<?php echo $_GET['tag'] ?>"> <div class="uk-form-row"> <input class="uk-button uk-button-primary uk-button-large uk-width-1-1" type="submit" class="alisubmit" value ="确认支付"> </div> </div> </form>
设置alipay.config.php配置文件,主要配置一下几个参数
$alipay_config['partner'] 设置签约账号ID
$alipay_config['key'] 设置MD5校验key
$alipay_config['notify_url'] 设置异步回调地址
$alipay_config['return_url'] 设置回调返回地址
$alipay_config['transport'] 设置协议类型,默认为http
$alipay_config['partner'] = 'xxxxxxxxxxxx';
//收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号
$alipay_config['seller_id'] = $alipay_config['partner'];
// MD5密钥,安全检验码,由数字和字母组成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm
$alipay_config['key'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
$alipay_config['notify_url'] = "http://xx.xx.xx.xx/pay/notify_url.php";
// 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
$alipay_config['return_url'] = "http://xx.xx.xx.xx/pay/return_url.php";
//签名方式
$alipay_config['sign_type'] = strtoupper('MD5');
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset']= strtolower('utf-8');
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = getcwd().'\\cacert.pem';
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
// 支付类型 ,无需修改
$alipay_config['payment_type'] = "1";
// 产品类型,无需修改
$alipay_config['service'] = "create_direct_pay_by_user";
更多关于PHP 接入支付宝即时到账功能请关注PHP中文网(www.php.cn)其它文章!