12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace refill\menggu;
- require_once(BASE_HELPER_RAPI_PATH . '/menggu/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;
- }
- }
- private function sign($params)
- {
- $params['appSecret'] = config::APP_SECRET;
- ksort($params);
- $content = '';
- foreach ($params as $key => $value) {
- if($this->check_empty($value) === false) {
- $content .= "{$key}={$value}&";
- }
- }
- $content = rtrim($content, '&');
- return md5($content);
- }
- private function check_empty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- public function notify($params)
- {
- $status = intval($params['orderStatus']);
- $order_sn = $params['outOrderId'];
- $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 === 2) {
- Log::record("mengu sms:{$params['ext1']}",Log::DEBUG);
- Model('')->table('refill_ext')->insert(['order_id' => $order_id, 'sms' => $params['ext1']]);
- $official_sn = $this->substr_content($params['ext1']);
- $data['official_sn'] = strtolower($official_sn) == 'null' ? '' : $official_sn;
- Model('refill_order')->edit($order_id, $data);
- return [$order_id, true, false,true];
- }
- elseif ($status === 3) {
- 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 '';
- }
- }
- }
|