RefillCallBack.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace refill\xiaoniu;
  3. require_once(BASE_HELPER_RAPI_PATH . '/xiaoniu/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. protected function check_empty($value)
  20. {
  21. if (!isset($value))
  22. return true;
  23. if ($value === null)
  24. return true;
  25. if (trim($value) === "")
  26. return true;
  27. return false;
  28. }
  29. private function sign($params)
  30. {
  31. $content = '';
  32. ksort($params);
  33. foreach ($params as $key => $val){
  34. if(false === $this->check_empty($val)) {
  35. $content .= "{$key}={$val}&";
  36. }
  37. }
  38. $content .= "key=".config::Key;
  39. return md5($content);
  40. }
  41. //[$order_id, $success, $can_try, $need_handle]
  42. public function notify($params)
  43. {
  44. $status = intval($params['status']);
  45. $order_sn = $params['mOrderNo'];
  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. Log::record("小牛油卡 官方凭证内容:{$params['content']}",Log::DEBUG);
  53. $official_sn = $this->substr_content($params['content']);
  54. $data['official_sn'] = strtolower($official_sn) == 'null' ? '' : $official_sn;
  55. Model('refill_order')->edit($order_id, $data);
  56. return [$order_id, true, false,true];
  57. }
  58. elseif ($status === 2) {
  59. return [$order_id, false, true,true];
  60. }
  61. else {
  62. return [$order_id, false, false,false];
  63. }
  64. }
  65. private function substr_content($content)
  66. {
  67. $data = explode(':',$content);
  68. if(count($data) > 1) {
  69. return $data[1];
  70. } else {
  71. return '';
  72. }
  73. }
  74. }