RefillCallBack.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace refill\youjunfeinoy;
  3. require_once(BASE_HELPER_RAPI_PATH . '/youjunfeinoy/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $input = $params;
  10. unset($input['sign']);
  11. $sign = $this->sign($input);
  12. if ($params['sign'] == $sign) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }
  18. protected function check_empty($value)
  19. {
  20. if (!isset($value))
  21. return true;
  22. if ($value === null)
  23. return true;
  24. if (trim($value) === "")
  25. return true;
  26. return false;
  27. }
  28. private function sign($params)
  29. {
  30. ksort($params);
  31. $body = "";
  32. $i = 0;
  33. foreach ($params as $k => $v) {
  34. if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
  35. if ($i == 0) {
  36. $body .= "{$k}" . "=" . urlencode($v);
  37. } else {
  38. $body .= "&" . "{$k}" . "=" . urlencode($v);
  39. }
  40. $i++;
  41. }
  42. }
  43. $body .= "&key=".config::KEY;
  44. return md5($body);
  45. }
  46. public function notify($params)
  47. {
  48. $status = $params['state'];
  49. $order_sn = $params['order_sn'];
  50. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  51. if (empty($order_info)) {
  52. return [false, false, false,false];
  53. }
  54. $order_id = $order_info['order_id'];
  55. if ($status === 'SUCCESS') {
  56. $data['ch_trade_no'] = $params['trade_no'];
  57. $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
  58. Model('refill_order')->edit($order_id, $data);
  59. return [$order_id, true, false,true];
  60. }
  61. elseif ($status === 'CANCEL') {
  62. Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['trade_no']]);
  63. return [$order_id, false, true,true];
  64. }
  65. else {
  66. return [$order_id, false, false,false];
  67. }
  68. }
  69. }