forked from ceroot/pay-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
577 changed files
with
71,794 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"type": "libray", | ||
"name": "zoujingli/think-alipay", | ||
"homepage": "https://github.com/zoujingli/think-alipay", | ||
"description": "AliPay development of SDK", | ||
"license": "MIT", | ||
"keywords": [ | ||
"think-alipay" | ||
], | ||
"require": { | ||
"php": ">=5.3.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"alipay\\": "./src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace alipay; | ||
|
||
use think\Loader; | ||
|
||
Loader::import('alipay.pay.service.AlipayTradeService'); | ||
loader::import('alipay.pay.buildermodel.AlipayTradeCloseContentBuilder'); | ||
|
||
/** | ||
* 统一收单交易关闭接口 | ||
* | ||
* 用法: | ||
* 调用 \alipay\Close::exec($query_no) 即可 | ||
* | ||
* ----------------- 求职 ------------------ | ||
* 姓名: zhangchaojie 邮箱: [email protected] 应届生 | ||
* 期望职位: PHP初级工程师 地点: 深圳(其他城市亦可) | ||
* 能力: | ||
* 1.熟悉小程序开发, 前后端皆可 | ||
* 2.后端, PHP基础知识扎实, 熟悉ThinkPHP5框架, 用TP5做过CMS, 商城, API接口 | ||
* 3.MySQL, Linux都在进行进一步学习 | ||
* | ||
*/ | ||
class Close | ||
{ | ||
// 商户订单号(out_trade_no) or 支付宝交易号(trade_no) 二选一 | ||
const QUERY_TYPE = 'trade_no'; | ||
|
||
public static function exec($query_no) | ||
{ | ||
// 1.构建请求参数 | ||
$RequestBuilder = new \AlipayTradeCloseContentBuilder(); | ||
if (self::QUERY_TYPE == 'trade_no') { | ||
$RequestBuilder->setTradeNo(trim($query_no)); | ||
} else { | ||
$RequestBuilder->setOutTradeNo(trim($query_no)); | ||
} | ||
|
||
// 2.获取配置 | ||
$config = config('alipay'); | ||
$aop = new \AlipayTradeService($config); | ||
|
||
// 3.发起请求 | ||
$response = $aop->Close($RequestBuilder); | ||
|
||
// 4.转为数组格式返回 | ||
$response = json_decode(json_encode($response), true); | ||
|
||
// 5.进行结果处理 | ||
if (!empty($response['code']) && $response['code'] != '10000') { | ||
self::processError('交易关闭接口出错, 错误码: '.$response['code'].' 错误原因: '.$response['sub_msg']); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* 统一错误处理接口 | ||
* @param string $msg 错误描述 | ||
*/ | ||
private static function processError($msg) | ||
{ | ||
throw new \think\Exception($msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace alipay; | ||
|
||
use think\Loader; | ||
|
||
Loader::import('alipay.pay.service.AlipayTradeService'); | ||
loader::import('alipay.pay.buildermodel.AlipayDataDataserviceBillDownloadurlQueryContentBuilder'); | ||
|
||
/** | ||
* 查询账单下载地址接口 | ||
* | ||
* 用法: | ||
* 调用 \alipay\Datadownload::exec($bill_type, $bill_date) 即可 | ||
* | ||
* ----------------- 求职 ------------------ | ||
* 姓名: zhangchaojie 邮箱: [email protected] 应届生 | ||
* 期望职位: PHP初级工程师 地点: 深圳(其他城市亦可) | ||
* 能力: | ||
* 1.熟悉小程序开发, 前后端皆可 | ||
* 2.后端, PHP基础知识扎实, 熟悉ThinkPHP5框架, 用TP5做过CMS, 商城, API接口 | ||
* 3.MySQL, Linux都在进行进一步学习 | ||
* | ||
*/ | ||
class Datadownload | ||
{ | ||
/** | ||
* 主入口 | ||
* @param string $bill_type trade/signcustomer, trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单; | ||
* @param string $bill_date 日期, 单格式为yyyy-MM-dd,月账单格式为yyyy-MM | ||
* 注意: | ||
* 1.当日或者当月日期为无效日期,毕竟没有过当日或者当月 | ||
* 2.如果是2017年7月,请填写2017-07,不能为2017-7 | ||
*/ | ||
public static function exec($bill_type, $bill_date) | ||
{ | ||
// 1.校检参数 | ||
self::checkParams($bill_type, $bill_date); | ||
|
||
// 2.设置请求参数 | ||
$RequestBuilder = new \AlipayDataDataserviceBillDownloadurlQueryContentBuilder(); | ||
$RequestBuilder->setBillType($bill_type); | ||
$RequestBuilder->setBillDate($bill_date); | ||
|
||
// 3.获取配置 | ||
$config = config('alipay'); | ||
$Response = new \AlipayTradeService($config); | ||
|
||
// 4.请求 | ||
$response = $Response->downloadurlQuery($RequestBuilder); | ||
|
||
// 5.转为数组格式返回 | ||
$response = json_decode(json_encode($response), true); | ||
|
||
// 6.进行结果处理 | ||
if (!empty($response['code']) && $response['code'] != '10000') { | ||
self::processError('查询账单接口出错, 错误码: '.$response['code'].' 错误原因: '.$response['sub_msg']); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* 校检参数 | ||
*/ | ||
private static function checkParams($bill_type, $bill_date) | ||
{ | ||
if (!in_array($bill_type, ['trade', 'signcustomer'])) { | ||
self::processError('账单类型不正确'); | ||
} | ||
|
||
if (!strtotime($bill_date)) { | ||
self::processError('日期格式不正确'); | ||
} | ||
} | ||
|
||
/** | ||
* 统一错误处理接口 | ||
* @param string $msg 错误描述 | ||
*/ | ||
private static function processError($msg) | ||
{ | ||
throw new \think\Exception($msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace alipay; | ||
|
||
use think\Loader; | ||
|
||
Loader::import('alipay.pay.service.AlipayTradeService'); | ||
|
||
/** | ||
* 支付回调处理类 | ||
* | ||
* 用法: | ||
* 调用 \alipay\Pagepay::pay($params) 即可 | ||
* | ||
* ----------------- 求职 ------------------ | ||
* 姓名: zhangchaojie 邮箱: [email protected] 应届生 | ||
* 期望职位: PHP初级工程师 地点: 深圳(其他城市亦可) | ||
* 能力: | ||
* 1.熟悉小程序开发, 前后端皆可 | ||
* 2.后端, PHP基础知识扎实, 熟悉ThinkPHP5框架, 用TP5做过CMS, 商城, API接口 | ||
* 3.MySQL, Linux都在进行进一步学习 | ||
* | ||
*/ | ||
class Notify | ||
{ | ||
/** | ||
* 异步通知校检, 包括验签和数据库信息与通知信息对比 | ||
* | ||
* @param array $params 数据库中查询到的订单信息 | ||
* @param string $params['out_trade_no'] 商户订单 | ||
* @param float $params['total_amount'] 订单金额 | ||
*/ | ||
public static function check($params) | ||
{ | ||
// 1.第一步校检签名 | ||
$config = config('alipay'); | ||
$alipaySevice = new \AlipayTradeService($config); | ||
$signResult = $alipaySevice->check($_POST); | ||
|
||
// 2.和数据库信息做对比 | ||
$paramsResult = self::checkParams($params); | ||
|
||
// 3.返回结果 | ||
if($signResult && $paramsResult) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* 判断两个数组是否一致, 两个数组的参数如下: | ||
* $params['out_trade_no'] 商户单号 | ||
* $params['total_amount'] 订单金额 | ||
* $params['app_id'] app_id号 | ||
*/ | ||
public static function checkParams($params) | ||
{ | ||
$notifyArr = [ | ||
'out_trade_no' => $_POST['out_trade_no'], | ||
'total_amount' => $_POST['total_amount'], | ||
'app_id' => $_POST['app_id'], | ||
]; | ||
$paramsArr = [ | ||
'out_trade_no' => $params['out_trade_no'], | ||
'total_amount' => $params['total_amount'], | ||
'app_id' => config('alipay.app_id'), | ||
]; | ||
$result = array_diff_assoc($paramsArr, $notifyArr); | ||
return empty($result) ? true : false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace alipay; | ||
|
||
use think\Loader; | ||
|
||
Loader::import('alipay.pay.service.AlipayTradeService'); | ||
loader::import('alipay.pay.buildermodel.AlipayTradePagePayContentBuilder'); | ||
|
||
/** | ||
* 电脑网站支付(扫码支付或账号支付) | ||
* | ||
* 用法: | ||
* 调用 \alipay\Pagepay::pay($params) 即可 | ||
* | ||
* ----------------- 求职 ------------------ | ||
* 姓名: zhangchaojie 邮箱: [email protected] | ||
* 期望职位: PHP初级工程师 地点: 深圳(其他城市亦可) | ||
* 能力: | ||
* 1.熟悉小程序开发, 前后端皆可 | ||
* 2.后端, PHP基础知识扎实, 熟悉ThinkPHP5框架, 用TP5做过CMS, 商城, API接口 | ||
* 3.MySQL, Linux都在进行进一步学习 | ||
*/ | ||
class Pagepay | ||
{ | ||
/** | ||
* 主入口 | ||
* @param array $params 支付参数, 具体如下 | ||
* @param string $params['subject'] 订单标题 | ||
* @param string $params['out_trade_no'] 订单商户号 | ||
* @param float $params['total_amount'] 订单金额 | ||
*/ | ||
public static function pay($params) | ||
{ | ||
// 1.校检参数 | ||
self::checkParams($params); | ||
|
||
// 2.构造参数 | ||
$payRequestBuilder = new \AlipayTradePagePayContentBuilder(); | ||
$payRequestBuilder->setSubject($params['subject']); | ||
$payRequestBuilder->setTotalAmount($params['total_amount']); | ||
$payRequestBuilder->setOutTradeNo($params['out_trade_no']); | ||
|
||
// 3.获取配置 | ||
$config = config('alipay'); | ||
$aop = new \AlipayTradeService($config); | ||
|
||
/** | ||
* 4.电脑网站支付请求(会自动跳转到支付页面) | ||
* @param $builder 业务参数,使用buildmodel中的对象生成。 | ||
* @param $return_url 同步跳转地址,公网可以访问 | ||
* @param $notify_url 异步通知地址,公网可以访问 | ||
* @return $response 支付宝返回的信息 | ||
*/ | ||
$aop->pagePay($payRequestBuilder, $config['return_url'],$config['notify_url']); | ||
} | ||
|
||
|
||
/** | ||
* 校检参数 | ||
*/ | ||
private static function checkParams($params) | ||
{ | ||
if (empty(trim($params['out_trade_no']))) { | ||
self::processError('商户订单号(out_trade_no)必填'); | ||
} | ||
|
||
if (empty(trim($params['subject']))) { | ||
self::processError('商品标题(subject)必填'); | ||
} | ||
|
||
if (floatval(trim($params['total_amount'])) <= 0) { | ||
self::processError('退款金额(total_amount)为大于0的数'); | ||
} | ||
} | ||
|
||
/** | ||
* 统一错误处理接口 | ||
* @param string $msg 错误描述 | ||
*/ | ||
private static function processError($msg) | ||
{ | ||
throw new \think\Exception($msg); | ||
} | ||
} |
Oops, something went wrong.