1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace app\api\controller;
- use app\models\store\StoreOrder;
- use app\models\user\UserBill;
- use app\phpPay\hpay\pay\AliLife;
- use app\Request;
- use crmeb\repositories\PaymentRepositories;
- use crmeb\services\AlipayService;
- use crmeb\services\SystemConfigService;
- use crmeb\services\UtilService;
- use crmeb\utils\Hook;
- class AlipayController
- {
- public function Notify()
- {
- $alipay = SystemConfigService::more(['alipay_app_id', 'alipay_pub_key', 'alipay_private_key', 'alipay_key']);
- $Pay = new AlipayService();
- $Pay->setAlipayPublicKey($alipay['alipay_key']);
- $result = $Pay->rsaCheck($_POST, $_POST['sign_type']);
- if ($result === true && $_POST['trade_status'] == 'TRADE_SUCCESS') {
- $out_trade_no = input('out_trade_no', '');
- if (($count = strpos(input('out_trade_no'), '_')) !== false) {
- $out_trade_no = substr(input('out_trade_no'), $count + 1);
- }
- parse_str(input('passback_params'), $attach);
- (new Hook(PaymentRepositories::class, 'wechat'))->listen($attach['attach'], $out_trade_no);
- echo 'success';
- exit();
- } else {
- echo 'error';
- exit();
- }
- }
- public function sdNotify(Request $request)
- {
- $post = $request->post();
- $data = json_decode($post['data']);
- $sing = json_decode($post['sign']);
- // $client = new AliLife();
- // //验签
- // try {
- // $verifyFlag = $client->verify($data, $sing);
- // if (!$verifyFlag) throw new Exception('签名失败');
- // } catch (\Exception $e) {
- // exit('签名失败');
- // }
- if ($data->body->orderStatus == 1) {
- $order = strstr($data->body->orderCode, '-', -1);
- if (StoreOrder::be(['order_id' => $order, 'paid' => 1])) return true;
- $res = StoreOrder::paySuccess($order, 'sdpay');
- if ($res){
- echo 'respCode=000000';
- exit();
- }else{
- echo 'error';
- exit();
- }
- }
- echo 'error';
- exit();
- }
- }
|