php整合支付宝,Thinkphp5.0整合支付宝在线下单

thinkphp5.0支付宝在线支付下单整个流程,包括创建订单、支付成功回调更新订单状态、最终跳转到商户订单详情页

43171696c72c47c4ced5632b96b50f3c.png

查看演示

下载资源:

17

次 下载资源

下载积分:

998

积分

支付宝在线支付控制器代码 public function alipay() {//发起支付宝支付

$order_no = date("YmdHis") . rand(100000, 999999);

if (request()->isPost()) { //支付表单提交,并唤起支付宝在线支付

//调用 application\index\model\Pay.php

$Pay = new Pay;

$result = $Pay->alipay([

'notify_url' => request()->domain() . url('index/index/alipay_notify'),

'return_url' => request()->domain() . url('index/index/alipay_return')."?order_no=".$order_no."&",

'out_trade_no' => input('post.orderid/s', '', 'trim,strip_tags'),

'subject' => input('post.subject/s', '', 'trim,strip_tags'),

'total_fee' => input('post.total_fee/f'), //订单金额,单位为元

'body' => input('post.body/s', '', 'trim,strip_tags'),

]);

if (!$result['code']) {

return $this->error($result['msg']);

}

return $result['msg'];

}

//创建订单

db('order_sucaihuo')->insert(array(

'order_no' => $order_no,

'order_money' => 0.1, //订单金额

'state' => 0, //支付状态 0 未支付, 1已支付

'uid' => 1, //用户uid

'addtime' => time(), //下单时间

'update_time' => 0 //支付时间

));

$this->view->orderid = $order_no;

return $this->fetch();

}

//支付宝客户端会每隔一段时间请求一次

public function alipay_notify() {//异步订单通知

$Pay = new Pay;

$result = $Pay->notify_alipay();

if ($result == 'success') {

$pay_info = $_REQUEST;

$order_no = $pay_info['out_trade_no'];

$order_info = db('order_sucaihuo')->where('order_no', $order_no)->find();

//若是未付款则更新

if ($order_info['state'] == 0) {

$data['trade_no'] = $pay_info['trade_no'];

$data['state'] = 1;

$data['update_time'] = time();

db('order_sucaihuo')->where("order_no", $order_no)->update($data);

}

}

//测试支付回调,linux记得开启777写入权限

file_put_contents("notify.txt", $result);

file_put_contents("request.txt", json_encode($_REQUEST));

}

压缩包有订单表 CREATE TABLE IF NOT EXISTS `order_sucaihuo` (

`id` int(11) unsigned NOT NULL,

`uid` int(11) NOT NULL,

`order_no` varchar(30) NOT NULL,

`trade_no` varchar(150) DEFAULT NULL COMMENT '交易号',

`order_money` decimal(10,2) DEFAULT '0.00',

`state` int(2) NOT NULL DEFAULT '0',

`addtime` int(10) NOT NULL,

`update_time` int(10) DEFAULT '0'

) ENGINE=MyISAM AUTO_INCREMENT=6718 DEFAULT CHARSET=utf8;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540937.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python函数示例_PHP closeir()函数与示例

python函数示例PHP Closedir()函数 (PHP closedir() function) The full form of closedir is "Close Directory", the function closedir() is used to close an opened directory. Closedir的完整格式为“ Close Directory” , 函数closedir()用于关闭打…

java宋江,Java编程内功-数据结构与算法「单链表」,

package com.structures.linkedlist;public class SingleLinkedListDemo {public static void main(String[] args) {HeroNode heroNode1 new HeroNode(1, "宋江", "及时雨");HeroNode heroNode2 new HeroNode(2, "卢俊义", "玉麒麟"…

智能家居逐渐融入AI技术 向大众市场扩张仍需时间

虽然智能家居变得越来越普遍,并且大众认知度越来越高,但是在这一技术变得像智能手机一样无处不在之前,OEM和服务提供商仍然有很长的路要走。 在2016年11月在硅谷举行的智能家居峰会上,代表们听到了来自整个价值链上的声音&#xf…

python 示例_Python使用示例设置add()方法

python 示例设置add()方法 (Set add() Method) add() method is used to add an element to the set, the method accepts an element and adds the elements to this set. add()方法用于将元素添加到集合中,该方法接受元素并将元素添加到该集合中。 Note: If the …

php怎么引用表单元素,表单元素:最全的各种html表单元素获取和使用方法总结...

表单是网页与用户的交互工具,由一个元素作为容器构成,封装其他任何数量的表单控件,还有其他任何元素里可用的标签,表单能够包含、、、、、等表单控件元素。表单元素有哪些呢?它包含了如下的这些元素,输入文…

数据中心部署气流遏制系统需要考虑的十大要素

数据中心气流遏制策略能够大幅提高传统数据中心制冷系统的可预测性和效率。事实上,绿色网格组织(The Green Grid)将气流管理策略称作“实施数据中心节能计划的起点”。但是,大多数已有数据中心由于受各种条件的制约,只…

JAVA语言异常,Java语言中的异常

1、异常分类从产生源头来看,Java语言中的异常可以分为两类:JVM抛出的异常。比如:访问null引用会引发NullPointerException;0作为除数,如9/0,JVM会抛出ArithmeticException;内存消耗完&#xff0…

使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法

新建generatorConfig.xml和build_mybatis.xml&#xff1a; jar下载 <dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.2</version></dependency> <depe…

java bitset_Java BitSet or()方法与示例

java bitsetBitSet类或()方法 (BitSet Class or() method) or() method is available in java.util package. or()方法在java.util包中可用。 or() method is used to perform logical OR between this BitSet and the given BitSet(bs). This BitSet is updated when either t…

matlab 细化函数,MATLAB图像处理工具箱函数(细化篇).doc

MATLAB图像处理工具箱函数(细化篇)第3章 MATLAB数字图像处理工具箱3.1 MATLAB图像预处理3.1.1 图像处理的基本操作1. 读入并显示一幅图像clear %清除所有的工作平台变量close all %关闭已打开的图形窗口Iimread (pout.tif); %读取图像pout.tif(该图像是图像处理工具箱自带的图像…

STM32启动解析

启动方式对的不同下载模式 STM32可以通过BOOT引脚的配置&#xff0c;来选择不同的启动模式------对应不同的下载方式。 仿真器下载—— 内部FLASH的启动方式 串口下载 —— 系统存储器的启动方式 内部SRAM一般不用&#xff0c;不讲 启动过程 以内部FLASH的启动方式为例&am…

OpenBSD基金会收到锤子科技约140万捐赠款

11月26日消息&#xff0c;给开源项目捐款一向是锤子科技发布会的传统&#xff0c;去年发布会的门票收入捐给了国人章亦春主导的开源项目OpenResty。今年&#xff0c;锤子科技选择将收益捐赠给OpenBSD基金会。OpenBSD基金会收到锤子科技约140万捐赠款 OpenBSD基金会11月23日发布…

自动化部署kvm虚拟机_自动化虚拟助手

自动化部署kvm虚拟机The automated virtual assistant or commonly called personal assistants, are developed to serve its users by performing some tasks, setting reminders and much more based on the input is given and local awareness. It is integrated with a l…

php 数据库编码,php怎么设置数据库编码方式

在php中&#xff0c;可以使用mysql_query()函数来设置mysql数据库的编码方式&#xff1b;具体方法&#xff1a;在mysql_connect()语句之后添加“mysql_query("set names 编码方式");”代码即可。本教程操作环境&#xff1a;windows7系统、PHP7.1版&#xff0c;DELL G…

mysql截取字符串与reverse函数

mysql的函数大全&#xff1a; http://www.jb51.net/Special/606.htm 这个网页上很多知识点&#xff0c;可以学习下&#xff0c;关于mysql的函数&#xff0c;也可以作为API查询&#xff1a; 这里只说下mysql的截取函数和reverse函数&#xff1a; MySQL 字符串截取函数&#xff1…

flask sql外键使用_如何在SQL中使用外键?

flask sql外键使用Basically, Foreign Key represents relationship between tables. 基本上&#xff0c; 外键代表表之间的关系 。 Syntax: 句法&#xff1a; column-name data_type (size) CONSTRAINT constraint-name References Table-name (Column-name)Example: 例&a…

php发展历,PHP的发展历程

PHP的发展历程了解一门语言&#xff0c;我们必须知道这门语言的发展史&#xff0c;现在我通过版本的变化以时间轴的形式来说明PHP的发展历程。1.1995年初PHP1.0诞生Rasmus Lerdof发明了PHP&#xff0c;这是简单的一套Perl脚本&#xff0c;用来跟踪访问者的信息。这个时候的PHP只…

中国互联网安全大会将召开 网络安全再获关注

从2016中国互联网安全大会筹委会获悉&#xff0c;将于8月16日在国家会议中心召开的第四届中国互联网安全大会筹备工作已全部就绪。 据经济参考报7月15日消息&#xff0c;中国网络空间安全协会副理事长、360公司总裁兼企业安全集团董事长齐向东表示&#xff0c;此次中国互联网安…

合并排序算法排序过程_外部合并排序算法

合并排序算法排序过程外部分类 (External sorting) External sorting is a technique in which the data is stored on the secondary memory, in which part by part data is loaded into the main memory and then sorting can be done over there. Then this sorted data wi…

php榛子云短信验证,java + maven +榛子云短信 实现发送短信验证码功能

如何使用java maven的项目环境发送短信验证码&#xff0c;本文使用的是榛子云短信的接口。下载下来是jar文件&#xff0c;需要将jar发布到本地的maven仓库中&#xff0c; 在cmd环境下输入:mvn install:install-file -DgroupIdcom.zhenzi -DartifactIdsms -Dversion1.0.0 -Dpac…