12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace refill\youjunfeinoy;
- require_once(BASE_HELPER_RAPI_PATH . '/youjunfeinoy/config.php');
- use refill;
- class RefillCallBack implements refill\IRefillCallBack
- {
- public function verify($params): bool
- {
- $input = $params;
- unset($input['sign']);
- $sign = $this->sign($input);
- if ($params['sign'] == $sign) {
- return true;
- } else {
- return false;
- }
- }
- protected function check_empty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- private function sign($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}" . "=" . urlencode($v);
- } else {
- $body .= "&" . "{$k}" . "=" . urlencode($v);
- }
- $i++;
- }
- }
- $body .= "&key=".config::KEY;
- return md5($body);
- }
- public function notify($params)
- {
- $status = $params['state'];
- $order_sn = $params['order_sn'];
- $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'];
- if ($status === 'SUCCESS') {
- $data['ch_trade_no'] = $params['trade_no'];
- $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
- Model('refill_order')->edit($order_id, $data);
- return [$order_id, true, false,true];
- }
- elseif ($status === 'CANCEL') {
- Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['trade_no']]);
- return [$order_id, false, true,true];
- }
- else {
- return [$order_id, false, false,false];
- }
- }
- }
|