您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何接支付宝

2024/4/2 16:32:39发布22次查看
首先导入支付宝的php sdk,下载地址,在支付宝文档中心下载移动支付(sdk&demo下载),解压之后打开服务端demo->readme.txt
我保留了(推荐学习:php视频教程)
重新命名为
分别给这五个文件加上命名空间
这四个文件的命名空间改为
alipay.class.php
<?phpnamespace extend\alipay;class alipay { public function pay(args){ /**************************请求参数**************************/ //支付类型 notify_url = return_url = out_trade_no = subject = "测试"; //必填 //付款金额 args['total']; //必填 //订单描述 anti_phishing_key = ""; //若要使用请调用类文件submit中的query_timestamp函数 //客户端的ip地址 parameter = array( "service" => "create_direct_pay_by_user", "partner" => trim(alipay_config['seller_id']), "payment_type" => notify_url, "return_url" => out_trade_no, "subject" => total_fee, "body" => show_url, "anti_phishing_key" => exter_invoke_ip, "_input_charset" => trim(strtolower(alipaysubmit = new lib\alipaysubmit(html_text = parameter,"get", "确认"); echo $html_text; }}
在config.php配置文件里要配置参数
然后新建控制器textcontroller.class.php
<?phpnamespace home\controller;use think\controller;use \extend\alipay as alipays;class textcontroller extends controller { public function index(){ out_trade_no = date('ymdhis'); _server['http_host']; out_trade_no, 'notify_url'=> baseurl.'/index.php/home/text/returnurl.html', 'total'=> s = new alipays\alipay(); args); } // 同步跳转 public function returnurl(){ alipaynotify = new alipays\lib\alipaynotify(verify_result = verify_result) {//验证成功 //商户订单号 _get['out_trade_no']; //支付宝交易号 _get['trade_no']; //交易状态 _get['trade_status']; if(_get['trade_status'] == 'trade_success') { //交易成功 }else { echo "trade_status=".alipay_config = c('alipay'); //计算得出通知验证结果 alipay_config); alipaynotify->verifynotify(); if(out_trade_no = trade_no = trade_status = _post['trade_status'] == 'trade_finished'||$_post['trade_status'] == 'trade_success') { //交易成功 } echo "success"; //请不要修改或删除 } else { //验证失败 echo "fail"; //调试用,写文本函数记录程序运行情况是否正常 //logresult("这里写入想要调试的代码变量值,或其他运行的结果记录"); } }}
然后
这样就成功完成简单的支付功能了
以上就是php如何接支付宝的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product