1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace kjwithdraw;
- class Kjwithdraw
- {
- /**
- * 除去数组中的空值和签名参数
- * @param $para 签名参数组
- * return 去掉空值与签名参数后的新签名参数组
- */
- function paraFilters($para) {
- $para_filter = array();
- foreach ($para as $key => $val) {
- if($key == "sign" || $val == "")continue;
- else $para_filter[$key] = $para[$key];
- }
- return $para_filter;
- }
- /**
- * 对数组排序
- * @param $para 排序前的数组
- * return 排序后的数组
- */
- function argSorts($para) {
- ksort($para);
- reset($para);
- return $para;
- }
- /**
- * 签名验证-快接支付
- * $datas 数据数组
- * $key 密钥
- */
- function sign($datas = array(), $key = ""){
- $str = urldecode(http_build_query($this->argSorts($this->paraFilters($datas))));
- // print_r($str);exit;
- $sign = md5($str."&key=".$key);
- return $sign;
- }
- /**
- * 签名验证-快接支付
- * $datas 数据数组
- * $key 密钥
- */
- function getdata($url, $param){
- $content = '';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
- curl_setopt($ch, CURLOPT_TIMEOUT,6);
- $content = curl_exec($ch);
- //如果发现异常,排查下curl错误
- //echo "curl错误:".curl_error($ch);
- curl_close($ch);
- return $content;
- }
- }
|