RefillCallBack.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace refill\menggu;
  3. require_once(BASE_HELPER_RAPI_PATH . '/menggu/config.php');
  4. use Log;
  5. use refill;
  6. class RefillCallBack implements refill\IRefillCallBack
  7. {
  8. public function verify($params): bool
  9. {
  10. $input = $params;
  11. unset($input['sign']);
  12. $sign = $this->sign($input);
  13. if ($params['sign'] == $sign) {
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }
  19. private function sign($params)
  20. {
  21. $params['appSecret'] = config::APP_SECRET;
  22. ksort($params);
  23. $content = '';
  24. foreach ($params as $key => $value) {
  25. if($this->check_empty($value) === false) {
  26. $content .= "{$key}={$value}&";
  27. }
  28. }
  29. $content = rtrim($content, '&');
  30. return md5($content);
  31. }
  32. private 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 = intval($params['orderStatus']);
  45. $order_sn = $params['outOrderId'];
  46. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  47. if (empty($order_info)) {
  48. return [false, false, false,false];
  49. }
  50. $order_id = $order_info['order_id'];
  51. if ($status === 2) {
  52. Log::record("mengu sms:{$params['ext1']}",Log::DEBUG);
  53. Model('')->table('refill_ext')->insert(['order_id' => $order_id, 'sms' => $params['ext1']]);
  54. $official_sn = config::official_sn($params['ext1']);
  55. Model('refill_order')->edit($order_id, ['official_sn' => $official_sn]);
  56. return [$order_id, true, false,true];
  57. }
  58. elseif ($status === 3) {
  59. return [$order_id, false, true,true];
  60. }
  61. else {
  62. return [$order_id, false, false,false];
  63. }
  64. }
  65. }