...
|
...
|
@@ -7,12 +7,13 @@ use app\mobile\model\CourseOrder; |
|
|
use app\mobile\model\SecretOrder;
|
|
|
use app\mobile\model\ScoreOrder;
|
|
|
use app\mobile\model\PackageOrder;
|
|
|
use app\mobile\model\RechargeOrder;
|
|
|
use app\mobile\model\User;
|
|
|
use addons\qiniu\library\Auth;
|
|
|
use app\common\model\Attachment;
|
|
|
|
|
|
/**
|
|
|
* 异步接口
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
class Notify extends Api
|
|
|
{
|
...
|
...
|
@@ -26,6 +27,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 课程---------------------------------------------------------------------
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifyCourse()
|
|
|
{
|
...
|
...
|
@@ -48,6 +50,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 课程-零元支付
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifyCourseZero($out_trade_no,$payamount,$paytype)
|
|
|
{
|
...
|
...
|
@@ -69,6 +72,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 课程-处理订单
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
private function handleCourseOrder($out_trade_no,$payamount,$paytype){
|
|
|
// 处理订单逻辑
|
...
|
...
|
@@ -84,6 +88,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 密卷-----------------------------------------------------------------------
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifySecret()
|
|
|
{
|
...
|
...
|
@@ -107,6 +112,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 密卷-零元支付
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifySecretZero($out_trade_no,$payamount,$paytype)
|
|
|
{
|
...
|
...
|
@@ -128,6 +134,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 密卷-处理订单
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
private function handleSecretOrder($out_trade_no,$payamount,$paytype){
|
|
|
// 处理订单逻辑
|
...
|
...
|
@@ -143,6 +150,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 积分----------------------------------------------------------------------
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifyScore()
|
|
|
{
|
...
|
...
|
@@ -166,6 +174,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 积分-零元支付
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifyScoreZero($out_trade_no,$payamount,$paytype)
|
|
|
{
|
...
|
...
|
@@ -187,6 +196,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 积分-处理订单
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
private function handleScoreOrder($out_trade_no,$payamount,$paytype){
|
|
|
// 处理订单逻辑
|
...
|
...
|
@@ -202,6 +212,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 企业套餐---------------------------------------------------------------------
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifyPackage()
|
|
|
{
|
...
|
...
|
@@ -225,6 +236,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 企业套餐-零元支付
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
public function notifyPackageZero($out_trade_no,$payamount,$paytype)
|
|
|
{
|
...
|
...
|
@@ -246,6 +258,7 @@ class Notify extends Api |
|
|
|
|
|
/**
|
|
|
* 企业套餐-处理订单
|
|
|
* @ApiInternal
|
|
|
*/
|
|
|
private function handlePackageOrder($out_trade_no,$payamount,$paytype){
|
|
|
// 处理订单逻辑
|
...
|
...
|
@@ -295,4 +308,151 @@ class Notify extends Api |
|
|
return json(['ret' => 'failed']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ios内购支付调试接口
|
|
|
*
|
|
|
* @ApiTitle (ios内购支付调试接口)
|
|
|
* @ApiSummary (ios内购支付调试接口)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="order_sn", type="string", required=true, description="订单号")
|
|
|
* @ApiParams (name="apple_receipt", type="string", required=true, description="ios支付成功返回的凭证数据")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
"data": {
|
|
|
}
|
|
|
})
|
|
|
*
|
|
|
*/
|
|
|
public function iosCheck(){
|
|
|
// 苹果内购的验证收据,由客户端传过来
|
|
|
$apple_receipt = input("post.apple_receipt", "");
|
|
|
$out_trade_no = input("post.order_sn", "");
|
|
|
$jsonData = ["receipt-data"=>$apple_receipt];
|
|
|
|
|
|
$jsonData1 = json_encode($jsonData);
|
|
|
$response = $this->http_post_data($jsonData1, true);
|
|
|
if($response->status==21007) {
|
|
|
$response = $this->http_post_data($jsonData1, false);
|
|
|
}else if ($response->status==21008) {
|
|
|
$response = $this->http_post_data($jsonData1, true);
|
|
|
}
|
|
|
if($response->status == 0){
|
|
|
// 允许名单数组
|
|
|
$bundlelist=['com.zhanghao.GMAT'];
|
|
|
$bundleid= $response->receipt->bundle_id;
|
|
|
if($bundleid && in_array($bundleid,$bundlelist)) {
|
|
|
// 最近交易
|
|
|
if($response->receipt->in_app && !empty($response->receipt->in_app)){
|
|
|
// 获取本次购买的信息
|
|
|
$in_app = end($response->receipt->in_app);
|
|
|
// 产品ID
|
|
|
$product_id = $in_app->product_id;
|
|
|
if($product_id && !empty($product_id)){
|
|
|
// 产品ID数组
|
|
|
$productids = [
|
|
|
"com.zhanghao.GMAT_12",
|
|
|
"com.zhanghao.GMAT_73",
|
|
|
"com.zhanghao.GMAT_113",
|
|
|
"com.zhanghao.GMAT_288",
|
|
|
"com.zhanghao.GMAT_488",
|
|
|
"com.zhanghao.GMAT_798"
|
|
|
];
|
|
|
if(in_array($product_id, $productids)){
|
|
|
// 查询该比交易是否已经成功
|
|
|
$transaction_id = $in_app->transaction_id;// 本次购买苹果内购的唯一标识,相当于订单号
|
|
|
$transactionWhere['transaction_id'] = $transaction_id;
|
|
|
$transactionWhere['pay_status'] = 1;
|
|
|
$havePay = RechargeOrder::where($transactionWhere)->find();
|
|
|
!empty($havePay) && $this->error('已经支付过了');
|
|
|
$haveOrder = RechargeOrder::where('order_sn',$out_trade_no)->find();
|
|
|
empty($haveOrder) && $this->error('订单不存在');
|
|
|
// 主动购买会有订单号
|
|
|
$order = RechargeOrder::where(['order_sn'=>$out_trade_no,'pay_status'=>0])->find();
|
|
|
if(!empty($order)){
|
|
|
//这里做逻辑处理
|
|
|
Db::startTrans();
|
|
|
$result = $order->isUpdate(true)->save([
|
|
|
'pay_status' => 1,
|
|
|
'pay_time' => time(),
|
|
|
'transaction_id' => $transaction_id,
|
|
|
'product_id' => $product_id,
|
|
|
]);
|
|
|
// 增加用户余额
|
|
|
$user = User::field('id,money')->where('id', $order['user_id'])->find();
|
|
|
$result_user = User::where('id', $order['user_id'])->setInc('money', $order['money']);
|
|
|
// 增加余额变动记录
|
|
|
$result_money_log = \app\common\model\MoneyLog::create([
|
|
|
'user_id' => $order['user_id'],
|
|
|
'money' => $order['money'],
|
|
|
'before' => $user['money'],
|
|
|
'after' => $user['money'] + $order['money'],
|
|
|
'memo' => '苹果内购充值余额',
|
|
|
'createtime' => time()
|
|
|
]);
|
|
|
if (!$result || !$result_user || !$result_money_log) {
|
|
|
Db::rollback();
|
|
|
$this->error('订单处理失败');
|
|
|
}
|
|
|
Db::commit();
|
|
|
}
|
|
|
$this->success('支付成功');
|
|
|
} else{
|
|
|
$this->error('非法product_id');
|
|
|
}
|
|
|
}else{
|
|
|
$this->error('produce_id不存在伪造充值');
|
|
|
}
|
|
|
}else{
|
|
|
$this->error('伪造充值');
|
|
|
}
|
|
|
}else{
|
|
|
$this->error('凭据bundleid不在白名单之内');
|
|
|
}
|
|
|
}else{
|
|
|
$code = $response->status;
|
|
|
$messagearr[21000] = "App Store无法读取你提供的JSON数据";
|
|
|
$messagearr[21002] = "收据数据不符合格式";
|
|
|
$messagearr[21003] = "收据无法被验证";
|
|
|
$messagearr[21004] = "你提供的共享密钥和账户的共享密钥不一致";
|
|
|
$messagearr[21005] = "收据服务器当前不可用";
|
|
|
$messagearr[21006] = "收据是有效的,但订阅服务已经过期。当收到这个信息时,解码后的收据信息也包含在返回内容中";
|
|
|
$messagearr[21007] = "收据信息是测试用(sandbox),但却被发送到产品环境中验证";
|
|
|
$messagearr[21008] = "收据信息是产品环境中使用,但却被发送到测试环境中验证";
|
|
|
$this->error($messagearr[$code]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* curl请求苹果app_store验证地址
|
|
|
* @param $data_string 验证字符串
|
|
|
* @param $istest 是否是测试地址 true正式地址 false测试地址
|
|
|
* @return mixed
|
|
|
*/
|
|
|
private function http_post_data($data_string, $istest) {
|
|
|
if ($istest) {
|
|
|
// 正式验证地址
|
|
|
$url = 'https://buy.itunes.apple.com/verifyReceipt';
|
|
|
} else {
|
|
|
// 测试验证地址
|
|
|
$url = 'https://sandbox.itunes.apple.com/verifyReceipt';
|
|
|
}
|
|
|
$curl_handle=curl_init();
|
|
|
curl_setopt($curl_handle,CURLOPT_URL, $url);
|
|
|
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER, true);
|
|
|
curl_setopt($curl_handle,CURLOPT_HEADER, 0);
|
|
|
curl_setopt($curl_handle,CURLOPT_POST, true);
|
|
|
curl_setopt($curl_handle,CURLOPT_POSTFIELDS, $data_string);
|
|
|
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
$response_json =curl_exec($curl_handle);
|
|
|
$response =json_decode($response_json);
|
|
|
curl_close($curl_handle);
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|