ThinkPHP $v) { $params[$k] = $v; } ksort($params); $formatStr = $this-formatParaMap($params, false); $formatStr .= "key=20170919ab6c1dsys6te2mwin8eretrp"; $formatStr = md5($formatStr); $result = strtoupper($formatStr); return $result; } // 格
$v) { $params[$k] = $v; } ksort($params); $formatStr = $this->formatParaMap($params, false); $formatStr .= "&key=20170919ab6c1dsys6te2mwin8eretrp"; $formatStr = md5($formatStr); $result = strtoupper($formatStr); return $result; } // 格式化参数 public function formatParaMap($params, $urlencode) { $buff = ""; ksort($params); foreach ($params as $k => $v) { if ($urlencode) { $v = urlencode($v); } $buff .= $k."=".$v."&"; } if (strlen($buff) > 0) { $reqPar = substr($buff, 0, strlen($buff)-1); } return $reqPar; } public function payToUser() { $dataArr = array(); $dataArr['amount'] = $this->amount; $dataArr['check_name'] = $this->check_name; $dataArr['desc'] = $this->desc; $dataArr['mch_appid'] = $this->mch_appid; $dataArr['mchid'] = $this->mchid; $dataArr['nonce_str'] = $this->nonce_str; $dataArr['openid'] = $this->openid; $dataArr['partner_trade_no'] = $this->partner_trade_no; $dataArr['re_user_name'] = $this->re_user_name; $dataArr['spbill_create_ip'] = $this->spbill_create_ip; $sign = $this->getSignStr($dataArr); // 组建xml参数 $data=""; // 发送请求 $res = $this->http_post($this->url, $data); // ... } public function http_post($url, $data) { $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url); curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); //两个证书(必填,请求需要双向证书。绝对地址) $zs1 = "/var/www/.../cert/apiclient_cert.pem"; $zs2 = "/var/www/.../cert/apiclient_key.pem"; curl_setopt ($ch,CURLOPT_SSLCERT,$zs1); curl_setopt ($ch,CURLOPT_SSLKEY,$zs2); curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); $info = curl_exec ( $ch ); curl_close ( $ch ); $info = simplexml_load_string($info, 'SimpleXMLElement', LIBXML_NOCDATA); $info = json_encode($info); $info = json_decode($info, true); return $info; } } ".$this->mch_appid." ".$this->mchid." ".$this->nonce_str." ".$orderid." ".$openid." ".$this->check_name." ".$this->re_user_name." ".$amount."".$this->desc." ".$this->spbill_create_ip." ".$sign."