'account', 'cash' => 'money', //'nickname' => 'nickname', ); $this->api = 'pay/index/order'; return $this->submit($param, $check); } # 通知处理 主要返回状态 2是成功 3是失败 public function notify($data) { $request = $data; unset($request['sign']); unset($request['s_order']); $sign = strtoupper($this->_sign($request, array('userid', 'orderid', 'sporderid', 'merchantsubmittime', 'resultno'))); if ($sign != $data['sign']) { return false; } $result = array(); $result['cash'] = 1; if ($data['resultno'] == 1) { $result['status'] = 2; } elseif ($data['resultno'] == 9) { $result['status'] = 3; } else { $result['status'] = 4; } if (isset($data['remark1']) && $data['remark1']) { # 流水号 $data['s_nubmer'] = $result['s_nubmer'] = $data['remark1']; } $result['yes'] = 'OK'; $result['data'] = $data; return $result; } # 数据响应格式处理 public function response($data) { $log['type'] = 'response'; $log['data'] = $data; $log['config'] = $this->data; $this->log($log); $array = $this->json_decode($data); if (!$array) { $msg = 'error'; } elseif (isset($array['code']) && $array['code'] == '0') { # 正确 $msg = 'ok'; } else { # 错误 $msg = isset($array['msg']) ? $array['msg'] : 'error'; } return array ( 'msg' => $msg, 'data' => $data, 'array' => $array, ); } # 主动查询接口 public function query($order) { $request['id'] = $this->mid; $request['out_trade_id'] = $order; $request['sign'] = $this->sign($request); $url = $this->host . 'pay/index/search'; $response = $this->curl('post', $url, $request); // print_r($response);die; $log['type'] = 'query_response'; $log['data'] = $response; $log['config'] = $this->data; $this->log($log); $array = $this->json_decode($response); $result = array(); $result['status'] = 3; if (isset($array['code']) && $array['code'] == '0000') { $result['status'] = 1; } if (isset($array['code']) && $array['code'] == '0004') { $result['status'] = 2; } if (isset($array['voucherNo']) && $array['voucherNo']) { # 流水号 $result['voucherNo'] = $array['voucherNo']; } return $result; } # 提交数据 private function submit($param, $check) { $param = $this->param($param, $check); if (is_string($param) || (is_array($param) && $param['status'] == 1)) { return $param; } $request = $param['detail']; $request['accounttype'] = 1; $request['id'] = $this->mid; $request['out_trade_id'] = $param['order']; //$request['back_url'] = $this->getNotify($param['order'], 1); $request['sign'] = $this->_sign($request, $this->sign); $url = $this->host . $this->api; $response = $this->curl('post', $url, $request); // print_r($response);die; $response = $this->response($response); $channel_order_id = ''; if (isset($response['array']['orderid'])) { $channel_order_id = $response['array']['orderid']; } $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); return $response['msg']; } private function _sign($request) { ksort($request); $signature_string = ''; foreach ($request as $k => $v) { if ($v && $k != 'datas') { $signature_string .= $v; } } $signature_string .= $this->token; return md5($signature_string); } public function isp($mobile) { //return $this->getphonetype($mobile); $url = 'http://cx.shouji.360.cn/phonearea.php?number=' . $mobile; $data = $this->curl('get', $url); if ($data) { $data = json_decode($data, true); if ($data && isset($data['data']['sp'])) { $sp = $data['data']['sp']; if ($sp == '移动') { return 1; } elseif ($sp == '联通') { return 2; } elseif ($sp == '电信') { return 3; } } } return 4; } }