|
@@ -8,7 +8,7 @@ use App\Models\CustomAmountRecord;
|
|
|
use Illuminate\Http\Request;
|
|
|
use App\Servers\WechatPay\Transfer;
|
|
|
use Kra8\Snowflake\Snowflake;
|
|
|
-use App\Servers\WechatMini\Mini;
|
|
|
+use App\Facades\Servers\WechatMini\Mini;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use WeChatPay\Formatter;
|
|
|
use WeChatPay\Crypto\AesGcm;
|
|
@@ -22,7 +22,7 @@ use WeChatPay\Crypto\Rsa;
|
|
|
* */
|
|
|
class WechatTransfer extends Api{
|
|
|
/**
|
|
|
- * 小程序微信支付下单 /api/wechat_pay/pay
|
|
|
+ * 小程序微信支付提现 /api/wechat_pay/transfer
|
|
|
*
|
|
|
* */
|
|
|
public function transfer(Custom $Custom,CustomAmount $CustomAmount,CustomAmountRecord $CustomAmountRecord)
|
|
@@ -31,6 +31,8 @@ class WechatTransfer extends Api{
|
|
|
$uid = $this->checkLogin();
|
|
|
$code = request('code','');
|
|
|
$amount = request('amount','');
|
|
|
+ if ($amount < 0.1) return json_send(['code'=>'error','msg'=>'提现失败','data'=>['error'=>'提现失败,超出最高提现额度']]);
|
|
|
+ if ($amount > 200) return json_send(['code'=>'error','msg'=>'提现失败','data'=>['error'=>'提现失败,超出最高提现额度']]);
|
|
|
// 获取余额信息
|
|
|
$amountInfo = $CustomAmount::query()->where(['custom_uid'=>$uid])->first();
|
|
|
if(!$amountInfo){
|
|
@@ -67,6 +69,7 @@ class WechatTransfer extends Api{
|
|
|
}
|
|
|
$Transfer = new Transfer();
|
|
|
$transferResult = $Transfer->pay($params);
|
|
|
+ Log::error('wechat/transfer','微信商户转账'.'返回'.json_encode($transferResult));
|
|
|
if (!$transferResult || $transferResult['state'] !== 'WAIT_USER_CONFIRM') return json_send(['code'=>'error','msg'=>'提现申请失败','data'=>'提现申请失败']);
|
|
|
$data = [
|
|
|
'custom_uid' => $uid,
|
|
@@ -78,7 +81,7 @@ class WechatTransfer extends Api{
|
|
|
'pay_type' => 1,
|
|
|
'balance' => $balance,
|
|
|
'description' => '余额提现',
|
|
|
- 'status' => 1,
|
|
|
+ 'status' => 0,
|
|
|
];
|
|
|
//写入余额记录
|
|
|
$recordResult = $CustomAmountRecord->add($data);
|
|
@@ -103,8 +106,9 @@ class WechatTransfer extends Api{
|
|
|
* 小程序微信支付回调 /api/wechat_pay/notify
|
|
|
*
|
|
|
* */
|
|
|
- public function notify(Custom $Custom,CustomScore $CustomScore)
|
|
|
+ public function notify()
|
|
|
{
|
|
|
+ Log::error('wechat/transfer_notify', '提现转账回调开始');
|
|
|
$content = file_get_contents("php://input");
|
|
|
if (!empty($content)) {
|
|
|
//直接json字符串
|
|
@@ -116,17 +120,17 @@ class WechatTransfer extends Api{
|
|
|
$params = [];
|
|
|
}
|
|
|
$post_data = $params;
|
|
|
- Log::log('notify_wechat_transfer', 'post_data:' . $post_data);
|
|
|
+ Log::error('wechat/transfer_notify', 'post_data:' . $post_data);
|
|
|
//获取headers参数
|
|
|
$headers = request()->header();
|
|
|
- Log::log('notify_wechat_transfer', '微信支付回调返回headers参数:' . json_encode($headers));
|
|
|
+ Log::error('wechat/transfer_notify', '微信支付回调返回headers参数:' . json_encode($headers));
|
|
|
|
|
|
$inWechatpaySignature = $headers['wechatpay-signature'][0];
|
|
|
$inWechatpayTimestamp = $headers['wechatpay-timestamp'][0];
|
|
|
$inWechatpaySerial = $headers['wechatpay-serial'][0];
|
|
|
$inWechatpayNonce = $headers['wechatpay-nonce'][0];
|
|
|
$inBody = $post_data;
|
|
|
- Log::log('notify_wechat_transfer', 'wechatpay-timestamp:' . $inWechatpayTimestamp);
|
|
|
+ Log::error('wechat/transfer_notify', 'wechatpay-timestamp:' . $inWechatpayTimestamp);
|
|
|
$apiv3Key = Config('wechatpay.APIV3');// 在商户平台上设置的APIv3密钥
|
|
|
// 根据通知的平台证书序列号,查询本地平台证书文件,
|
|
|
$platformCertificateFilePath = Config('wechatpay.platformCertificate');
|
|
@@ -134,14 +138,14 @@ class WechatTransfer extends Api{
|
|
|
try {
|
|
|
// 检查通知时间偏移量,允许5分钟之内的偏移
|
|
|
$timeOffsetStatus = 300 >= abs(Formatter::timestamp() - (int)$inWechatpayTimestamp);
|
|
|
- Log::log('notify_wechat_transfer', '时间偏移量:' . $timeOffsetStatus);
|
|
|
+ Log::error('notify_wechat_transfer', '时间偏移量:' . $timeOffsetStatus);
|
|
|
$verifiedStatus = Rsa::verify(
|
|
|
// 构造验签名串
|
|
|
Formatter::joinedByLineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
|
|
|
$inWechatpaySignature,
|
|
|
$platformPublicKeyInstance
|
|
|
);
|
|
|
- Log::log('notify_wechat_transfer', '验签:' . $verifiedStatus.'验签inWechatpayTimestamp:' . $inWechatpayTimestamp.'验签verifiedStatus:' . $inWechatpayNonce);
|
|
|
+ Log::error('wechat/transfer_notify', '验签:' . $verifiedStatus.'验签inWechatpayTimestamp:' . $inWechatpayTimestamp.'验签verifiedStatus:' . $inWechatpayNonce);
|
|
|
if ($timeOffsetStatus && $verifiedStatus) {
|
|
|
// 转换通知的JSON文本消息为PHP Array数组
|
|
|
$inBodyArray = (array)json_decode($inBody, true);
|
|
@@ -155,8 +159,8 @@ class WechatTransfer extends Api{
|
|
|
$inBodyResource = AesGcm::decrypt($ciphertext, $apiv3Key, $nonce, $aad);
|
|
|
// 把解密后的文本转换为PHP Array数组
|
|
|
$inBodyResourceArray = (array)json_decode($inBodyResource, true);
|
|
|
- Log::log('notify_wechat_transfer', '打印解密后的结果:' . json_encode($inBodyResourceArray));
|
|
|
- Log::log('notify_wechat_transfer', '参数:' . $inBodyResourceArray['trade_state'] . '订单号' . $inBodyResourceArray['out_trade_no'] . '微信支付号' . $inBodyResourceArray['transaction_id']);
|
|
|
+ Log::error('wechat/transfer_notify', '打印解密后的结果:' . json_encode($inBodyResourceArray));
|
|
|
+ Log::error('wechat/transfer_notify', '参数:' . $inBodyResourceArray['trade_state'] . '订单号' . $inBodyResourceArray['out_trade_no'] . '微信支付号' . $inBodyResourceArray['transaction_id']);
|
|
|
if ($inBodyResourceArray['trade_state'] == "SUCCESS") {
|
|
|
$status = 2;
|
|
|
//更新余额订单状态
|
|
@@ -165,12 +169,12 @@ class WechatTransfer extends Api{
|
|
|
'status'=>$status,
|
|
|
];
|
|
|
$res = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->update($data);
|
|
|
- Log::log('notify_wechat_transfer', '更新余额记录,snowflake_id:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
|
+ Log::error('wechat/transfer_notify', '更新余额记录,snowflake_id:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
|
if (!$res) {
|
|
|
- Log::log('notify_wechat_transfer', '更新余额记录失败' . json_encode($res));
|
|
|
+ Log::error('wechat/transfer_notify', '更新余额记录失败' . json_encode($res));
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
- Log::log('notify_wechat_pay', '支付回调完成 通知返回' . json_encode($data));
|
|
|
+ Log::error('wechat/transfer_notify', '支付回调完成 通知返回' . json_encode($data));
|
|
|
}elseif ($inBodyResourceArray['trade_state'] == "FAIL"){
|
|
|
$status = 3;
|
|
|
//更新余额订单状态
|
|
@@ -178,30 +182,30 @@ class WechatTransfer extends Api{
|
|
|
'status'=>$status
|
|
|
];
|
|
|
$res = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->update($data);
|
|
|
- Log::log('notify_wechat_transfer', '更新余额记录,snowflake_id:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
|
+ Log::error('wechat/transfer_notify', '更新余额记录,snowflake_id:'.$inBodyResourceArray['out_bill_no'].';'. json_encode($res));
|
|
|
if (!$res) {
|
|
|
- Log::log('notify_wechat_transfer', '更新余额记录失败' . json_encode($res));
|
|
|
+ Log::error('wechat/transfer_notify', '更新余额记录失败' . json_encode($res));
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
$amountInfo = CustomAmountRecord::query()->where('out_bill_no','=',$inBodyResourceArray['out_bill_no'])->first();
|
|
|
if ($amountInfo){
|
|
|
- Log::log('notify_wechat_transfer', '获取余额记录信息失败' . json_encode($res));
|
|
|
+ Log::error('wechat/transfer_notify', '获取余额记录信息失败' . json_encode($res));
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
//退回余额
|
|
|
$res = CustomAmount::query()->where('uid','=',$amountInfo['custom_uid'])->increment('amount',$amountInfo['amount']);
|
|
|
if (!$res){
|
|
|
- Log::log('notify_wechat_pay', '退回余额失败' . json_encode($amountInfo));
|
|
|
+ Log::error('wechat/transfer_notify', '退回余额失败' . json_encode($amountInfo));
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
- Log::log('notify_wechat_pay', '回调完成 通知返回' . json_encode($amountInfo));
|
|
|
+ Log::error('wechat/transfer_notify', '回调完成 通知返回' . json_encode($amountInfo));
|
|
|
}
|
|
|
return json_send(['code'=>'SUCCESS']);
|
|
|
}else{
|
|
|
return json_send(['code'=>'FAIL']);
|
|
|
}
|
|
|
}catch (\Exception $e){
|
|
|
- Log::log('notify_wechat_transfer', '回调失败getMessage:' . $e->getMessage());
|
|
|
+ Log::error('wechat/transfer_notify', '回调失败getMessage:' . $e->getMessage());
|
|
|
}
|
|
|
return json_send(['code'=>'SUCCESS']);
|
|
|
}
|