123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace refill\gftd;
- require_once(BASE_HELPER_RAPI_PATH . '/gftd/config.php');
- use refill;
- class RefillCallBack implements refill\IRefillCallBack
- {
- public function verify($params): bool
- {
- $input = $params;
- unset($input['signature']);
- $sign = $this->sign($input);
- if ($params['signature'] == $sign) {
- return true;
- } else {
- return false;
- }
- }
- private function sign($params)
- {
- $body = $this->body($params);
- $body .= config::APP_SECRET;
- return md5($body);
- }
- protected function check_empty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- private function body($params)
- {
- ksort($params);
- $body = "";
- $i = 0;
- foreach ($params as $k => $v)
- {
- if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
- {
- if ($i == 0) {
- $body .= "{$k}" . "=" . $v;
- } else {
- $body .= "&" . "{$k}" . "=" . $v;
- }
- $i++;
- }
- }
- return $body;
- }
- public function notify($params)
- {
- $status = intval($params['status']);
- $order_sn = $params['channelOrderNumber'];
- $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
- if (empty($order_info)) {
- return [false, false, false,false];
- }
- $order_id = $order_info['order_id'];
- $data['official_sn'] = $params['voucher'];
- $data['ch_trade_no'] = $params['orderNumber'];
- $data['err_msg'] = $params['message'];
- Model('refill_order')->edit($order_id, $data);
- //[$order_id, 成功失败, 是否能重试,接下来是否需要处理]
- if ($status === 101) {
- return [$order_id, true, false,true];
- }
- elseif ($status === 109) {
- $this->onError($params['message'],$order_id);
- return [$order_id, false, false,true];
- }
- elseif ($status === 120) {
- return [$order_id, false, false,false];
- }
- else {
- return [$order_id, false, false,false];
- }
- }
- public function onError($msg,$order_id)
- {
- if(in_array($msg,config::BlackMsgs))
- {
- $refill = Model('refill_order');
- $order = $refill->getOrderInfo(['order_id' => $order_id]);
- if(empty($order)) return false;
- $card_no = $order['card_no'];
- if(!empty($card_no)) {
- refill\util::set_black($card_no);
- return true;
- }
- }
- return false;
- }
- }
|