RefillCallBack.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace refill\jumi;
  3. require_once(BASE_HELPER_RAPI_PATH . '/jumi/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. $content = '';
  31. ksort($params);
  32. foreach ($params as $key => $val){
  33. $content .= "{$key}={$val}&";
  34. }
  35. $content .= "token=".config::Token;
  36. return md5($content);
  37. }
  38. //[$order_id, $success, $can_try, $need_handle]
  39. public function notify($params)
  40. {
  41. $status = intval($params['status']);
  42. $order_sn = $params['order_no'];
  43. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  44. if (empty($order_info)) {
  45. return [false, false, false,false];
  46. }
  47. $order_id = $order_info['order_id'];
  48. if ($status === 1) {
  49. $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
  50. Model('refill_order')->edit($order_id, $data);
  51. return [$order_id, true, false,true];
  52. }
  53. elseif ($status === 3) {
  54. return [$order_id, false, true,true];
  55. }
  56. else {
  57. return [$order_id, false, false,false];
  58. }
  59. }
  60. }