RefillCallBack.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace refill\dinghui;
  3. require_once(BASE_HELPER_RAPI_PATH . '/dinghui/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $res = $this->decrypt($params);
  10. if ($res == 1) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private function decrypt($params)
  17. {
  18. $sign = $params['sign'];
  19. unset($params['sign']);
  20. $content = '';
  21. ksort($params);
  22. foreach ($params as $key => $val){
  23. $content .= "{$key}={$val}&";
  24. }
  25. $content = rtrim($content,'&');
  26. return openssl_verify($content, hex2bin($sign), config::PUBLIC_KEY);
  27. }
  28. private function message_decrypt($message)
  29. {
  30. return json_decode(openssl_decrypt($message, 'AES-256-ECB', config::AES_KEY, 0, ''));
  31. }
  32. public function notify($params)
  33. {
  34. $data = $this->message_decrypt($params['message']);
  35. $status = $data->charge_result;
  36. $order_sn = $data->app_order_no;
  37. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  38. if (empty($order_info)) {
  39. return [false, false, false,false];
  40. }
  41. $order_id = $order_info['order_id'];
  42. if ($status === 'SUCCESS') {
  43. return [$order_id, true, false,true];
  44. }
  45. elseif ($status === 'FAILED') {
  46. return [$order_id, false, true,true];
  47. }
  48. else {
  49. return [$order_id, false, false,false];
  50. }
  51. }
  52. }