xmlToArray($resp); if (empty($resp)) { return [false, '网络错误']; } else { $code = $resp['code']; if (in_array($code, [100, 101, 102, 103, 888])) { $order_status = intval($resp['data']['order_status']); if ($order_status === 0) { $updata['official_sn'] = $resp['data']['cp_id']; Model('refill_order')->edit($refill_info['order_id'], $updata); $order_state = ORDER_STATE_SUCCESS; } elseif ($order_status === 3) { $order_state = ORDER_STATE_CANCEL; } elseif (in_array($order_status, [1, 2])) { $order_state = ORDER_STATE_SEND; } else { return [false, $resp['msg']]; } return [true, $order_state]; } elseif ($code === 258 && (time() - $refill_info['commit_time'] >= 600)) { return [true, ORDER_STATE_NOEXIST]; } else { return [false, $resp['msg']]; } } } } public function balance() { $params['mer_id'] = config::MER_ID; $params['request_time'] = date("YmdHis"); $content = "{$params['mer_id']}{$params['request_time']}".config::KEY; $params['sign'] = md5($content); $resp = http_request(config::BALANCE_URL, $params, 'GET', false, []); if (empty($resp)) { return [false, '网络错误']; } else { Log::record($resp, Log::DEBUG); $resp = $this->xmlToArray($resp); if (empty($resp)) { return [false, '网络错误']; } elseif($resp['code'] == 100) { return [true, $resp['money']]; } else { return [false, $resp['msg']]; } } } private function sign($params) { $userid = config::MER_ID; $key = config::KEY; $content = "{$userid}{$params['mer_oid']}{$params['product_face']}{$params['product_num']}{$params['recharge_amount']}{$params['phone_no']}{$params['notify_url']}"; $content .= "{$params['request_time']}{$params['recharge_type']}{$key}"; return md5($content); } public function xmlToArray($xml) { $replace_str = str_replace(' ','','encoding="gbk"'); $xml = mb_convert_encoding($xml,"UTF-8","gbk"); $xml = str_replace($replace_str, "encoding='utf-8'", $xml); return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); } }