binding($data,$appkey,$path); return $content; } //获取openid public function getopenid($data,$appkey) { $path = self::$getopenid; $content = $this->binding($data,$appkey,$path); return $content; } //绑定商家公用请求方法 public function binding($data,$appkey,$path) { header("Content-type: text/html; charset=utf-8"); $data['timestamp'] = time(); $data['nonce_str'] = $this->randomkeys(32); $data['sign'] = $this->sign($data,$appkey); $content = $this->request_post($path,$data); return $content; } //获取余额详情 public function getbalance($data,$appkey) { $path = self::$balance; $content = $this->uu_request($data,$appkey,$path); return $content; } //充值 public function recharge($data,$appkey) { $path = self::$recharge; $content = $this->uu_request($data,$appkey,$path); return $content; } //订单价格 public function getorderprice($data,$appkey) { $path = self::$getorderprice; $content = $this->uu_request($data,$appkey,$path); return $content; } //下单 public function addorder($data,$appkey) { $path = self::$addorder; $content = $this->uu_request($data,$appkey,$path); return $content; } //取消订单 public function cancelorder($data,$appkey) { $path = self::$cancelorder; $content = $this->uu_request($data,$appkey,$path); return $content; } //订单详情 public function getorderdetail($data,$appkey) { $path = self::$getorderdetail; $content = $this->uu_request($data,$appkey,$path); return $content; } //获取已开通的城市列表 public function getcitylist() { $content = $this->uu_request(); } //公共请求方法 private function uu_request($data,$appkey,$path) { header("Content-type: text/html; charset=utf-8"); $data['nonce_str'] = $this->randomkeys(32); $data['timestamp'] = time(); $data['sign'] = $this->sign($data,$appkey); $content = $this->request_post($path,$data); return $content; } private function request_post($url = '', $post_data = array()) { if (empty($url) || empty($post_data)) { return false; } $arr = []; foreach ($post_data as $key => $value) { $arr[] = $key.'='.$value; } $curlPost = implode('&', $arr); $postUrl = $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$postUrl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $data = curl_exec($ch); curl_close($ch); return $data; } // 生成随机字符串 private function randomkeys($length) { $pattern = '1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLOMNOPQRSTUVWXYZ,./&l t;>?;#:@~[]{}-_=+)(*&^%$?!'; //字符池 $key = ''; for ($i = 0; $i < $length; $i++) { $key .= $pattern{mt_rand(0, 35)}; //生成php随机数 } return $key; } // 生成签名 private function sign($data, $appkey) { ksort($data); $arr = ''; foreach ($data as $key => $value) { $arr .= $key.'='.$value.'&'; } $arr .= 'key='.$appkey; $str = strtoupper($arr); return strtoupper(md5($str)); } }