You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Api\CommonController;
  4. use Illuminate\Http\Request;
  5. use App\Common\ReturnData;
  6. use App\Common\Token;
  7. use App\Http\Model\UserMoney;
  8. class PaymentNotifyController extends CommonController
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. }
  14. public function WxPayAppNotify(Request $request)
  15. {
  16. $options = config('weixin.abmapp');
  17. $app = new \EasyWeChat\Foundation\Application($options);
  18. $response = $app->payment->handleNotify(function($notify, $successful)
  19. {
  20. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  21. $order = 查询订单($notify->out_trade_no);
  22. if (!$order) { // 如果订单不存在
  23. return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  24. }
  25. // 如果订单存在
  26. // 检查订单是否已经更新过支付状态
  27. if ($order->paid_at) // 假设订单字段“支付时间”不为空代表已经支付
  28. {
  29. return true; // 已经支付成功了就不再更新了
  30. }
  31. // 用户是否支付成功
  32. if ($successful)
  33. {
  34. // 不是已经支付状态则修改为已经支付状态
  35. $order->paid_at = time(); // 更新支付时间为当前时间
  36. $order->status = 'paid';
  37. }
  38. else
  39. {
  40. // 用户支付失败
  41. $order->status = 'paid_fail';
  42. }
  43. $order->save(); // 保存订单
  44. return true; // 返回处理完成
  45. });
  46. return $response;
  47. }
  48. public function AlipayAppNotify($config('alipay.app_alipay'))
  49. {
  50. require_once base_path('resources/org/alipay_app').'/AopClient.php';
  51. $aop = new \AopClient;
  52. $aop->alipayrsaPublicKey = $config['alipayrsaPublicKey'];
  53. $flag = $aop->rsaCheckV1($_REQUEST, NULL, "RSA2");
  54. //支付成功
  55. if($flag)
  56. {
  57. $out_trade_no = $_REQUEST['out_trade_no'];
  58. }
  59. }
  60. }