1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace refill\xiaoniu;
- require_once(BASE_HELPER_RAPI_PATH . '/xiaoniu/config.php');
- use Log;
- 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)
- {
- $content = '';
- ksort($params);
- foreach ($params as $key => $val){
- if(false === $this->check_empty($val)) {
- $content .= "{$key}={$val}&";
- }
- }
- $content .= "key=".config::Key;
- return md5($content);
- }
- //[$order_id, $success, $can_try, $need_handle]
- public function notify($params)
- {
- $status = intval($params['status']);
- $order_sn = $params['mOrderNo'];
- $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 === 1) {
- Log::record("小牛油卡 官方凭证内容:{$params['content']}",Log::DEBUG);
- Model('')->table('refill_ext')->insert(['order_id' => $order_id, 'sms' => $params['content']]);
- $official_sn = $this->substr_content($params['content']);
- $data['official_sn'] = strtolower($official_sn) == 'null' ? '' : $official_sn;
- Model('refill_order')->edit($order_id, $data);
- return [$order_id, true, false,true];
- }
- elseif ($status === 2) {
- return [$order_id, false, true,true];
- }
- else {
- return [$order_id, false, false,false];
- }
- }
- private function substr_content($content)
- {
- $data = explode(':',$content);
- if(count($data) > 1) {
- return $data[1];
- } else {
- return '';
- }
- }
- }
|