RefillCallBack.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace refill\jike;
  3. require_once(BASE_HELPER_RAPI_PATH . '/jike/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. public static function sign($params)
  19. {
  20. ksort($params);
  21. $content = '';
  22. if(isset($params['refundAmount'])) {
  23. $params['refundAmount'] = number_format($params['refundAmount'], 2);
  24. }
  25. if(isset($params['amount'])) {
  26. $params['amount'] = number_format($params['amount'], 2);
  27. }
  28. if(isset($params['settlementAmount'])) {
  29. $params['settlementAmount'] = number_format($params['settlementAmount'], 2);
  30. }
  31. foreach ($params as $key => $value) {
  32. if(self::check_empty($value) === false) {
  33. $content .= "{$key}={$value}&";
  34. }
  35. }
  36. $content .= 'appSecret='.config::APP_SECRET;
  37. return md5($content);
  38. }
  39. public static function check_empty($value)
  40. {
  41. if (!isset($value))
  42. return true;
  43. if ($value === null)
  44. return true;
  45. if (trim($value) === "")
  46. return true;
  47. return false;
  48. }
  49. public function notify($params)
  50. {
  51. $order_sn = $params['outOrderNo'];
  52. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  53. if (empty($order_info)) {
  54. return [false, false, false,false];
  55. }
  56. $order_id = $order_info['order_id'];
  57. $status = intval($params['status']);
  58. $updata['ch_trade_no'] = $params['orderNo'];
  59. Model('refill_order')->edit($order_id, $updata);
  60. if ($status === 1) {
  61. $updata['official_sn'] = strtolower($params['officialNo']) == 'null' ? '' : $params['officialNo'];
  62. Model('refill_order')->edit($order_id, $updata);
  63. return [$order_id, true, false, true];
  64. } elseif ($status === 2 || $status === 3) {
  65. return [$order_id, false, true, true];
  66. } else {
  67. return [$order_id, false, false, false];
  68. }
  69. }
  70. }