RefillCallBack.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace refill\yuke;
  3. require_once(BASE_HELPER_RAPI_PATH . '/yuke/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $sign = $this->sign($params);
  10. if ($params['sign'] == $sign) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private function sign($params)
  17. {
  18. $key = config::SECRET_KEY;
  19. $content = "tPfChannelId={$params['tPfChannelId']}&rechargeAccount={$params['rechargeAccount']}&rechargeAmount={$params['rechargeAmount']}&orderType={$params['orderType']}";
  20. $content .= "&orderStatus={$params['orderStatus']}&orderSn={$params['orderSn']}&outOrderId={$params['outOrderId']}&createTime={$params['createTime']}";
  21. $content .= "&updatedTime={$params['updatedTime']}&secret_key={$key}";
  22. return strtoupper(md5($content));
  23. }
  24. //[$order_id, $success, $can_try, $need_handle]
  25. public function notify($params)
  26. {
  27. $status = intval($params['orderStatus']);
  28. $order_sn = $params['outOrderId'];
  29. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  30. if (empty($order_info)) {
  31. return [false, false, false,false];
  32. }
  33. $order_id = $order_info['order_id'];
  34. if ($status === 2) {
  35. $data['official_sn'] = $params['data']['callbackOtherAttr']['cert_no'];
  36. Model('refill_order')->edit($order_id, $data);
  37. return [$order_id, true, false,true];
  38. }
  39. elseif ($status === 3 || $status === 4) {
  40. return [$order_id, false, true,true];
  41. }
  42. else {
  43. return [$order_id, false, false,false];
  44. }
  45. }
  46. }