RefillCallBack.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace refill\yuke_dx;
  3. require_once(BASE_HELPER_RAPI_PATH . '/yuke_dx/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. $params['rechargeAmount'] = number_format($params['rechargeAmount'], 3);
  19. $key = config::SECRET_KEY;
  20. $content = "tPfChannelId={$params['tPfChannelId']}&rechargeAccount={$params['rechargeAccount']}&rechargeAmount={$params['rechargeAmount']}&orderType={$params['orderType']}";
  21. $content .= "&orderStatus={$params['orderStatus']}&orderSn={$params['orderSn']}&outOrderId={$params['outOrderId']}&createTime={$params['createTime']}";
  22. $content .= "&updatedTime={$params['updatedTime']}&secret_key={$key}";
  23. return strtoupper(md5($content));
  24. }
  25. //[$order_id, $success, $can_try, $need_handle]
  26. public function notify($params)
  27. {
  28. $status = intval($params['orderStatus']);
  29. $order_sn = $params['outOrderId'];
  30. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  31. if (empty($order_info)) {
  32. return [false, false, false,false];
  33. }
  34. $order_id = $order_info['order_id'];
  35. if ($status === 2) {
  36. $data['official_sn'] = $params['callbackOtherAttr']['cert_no'];
  37. Model('refill_order')->edit($order_id, $data);
  38. return [$order_id, true, false,true];
  39. }
  40. elseif ($status === 3 || $status === 4) {
  41. return [$order_id, false, true,true];
  42. }
  43. else {
  44. return [$order_id, false, false,false];
  45. }
  46. }
  47. }