RefillCallBack.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace refill\jinxin;
  3. require_once(BASE_HELPER_RAPI_PATH . '/jinxin/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. unset($input['supplierNo']);
  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. $content = '';
  22. ksort($params);
  23. foreach ($params as $key => $val){
  24. if(false === $this->check_empty($val)) {
  25. $content .= "{$key}={$val}&";
  26. }
  27. }
  28. $key = config::KEY;
  29. $content .= "appKey={$key}";
  30. return strtoupper(md5($content));
  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 = intval($params['status']);
  45. $order_sn = $params['requestId'];
  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 === 1) {
  52. Model('refill_order')->edit($order_id, ['official_sn' =>$params['supplierNo'] ]);
  53. return [$order_id, true, false,true];
  54. }
  55. elseif ($status === 2) {
  56. return [$order_id, false, true,true];
  57. }
  58. else {
  59. return [$order_id, false, false,false];
  60. }
  61. }
  62. }