RefillCallBack.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace refill\wangxin;
  3. require_once(BASE_HELPER_RAPI_PATH . '/wangxin/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $sign = $this->sign($params);
  10. if ($sign === 1) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private function sign($params)
  17. {
  18. $sign = $params['sign'];
  19. unset($params['ext_content']);
  20. unset($params['sign']);
  21. $content = '';
  22. ksort($params);
  23. foreach ($params as $key => $val)
  24. {
  25. if (false === $this->check_empty($val)) {
  26. $content .= "{$key}={$val}&";
  27. }
  28. }
  29. $content = rtrim($content, '&');
  30. return openssl_verify($content, base64_decode($sign), config::PROVIDER_PUBLIC_KEY);
  31. }
  32. protected function check_empty($value)
  33. {
  34. if (!isset($value))
  35. return true;
  36. if ($value === null)
  37. return true;
  38. if (trim($value) === "")
  39. return true;
  40. return false;
  41. }
  42. public function notify($params)
  43. {
  44. $status = $params['status'];
  45. $order_sn = $params['kh_order_id'];
  46. $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
  47. if (empty($order_info)) {
  48. return [false, false, false, false, ''];
  49. }
  50. $official_sn = '';
  51. $order_id = $order_info['order_id'];
  52. if ($status === '3') {
  53. $official_sn = strtolower($params['ext_content'] ?? '');
  54. $data['official_sn'] = $official_sn;
  55. Model('refill_order')->edit($order_id, $data);
  56. return [$order_id, true, false, true, $official_sn];
  57. } elseif ($status === '2') {
  58. return [$order_id, false, true, true, $official_sn];
  59. } else {
  60. return [$order_id, false, false, false, $official_sn];
  61. }
  62. }
  63. }