ThinkPHP简易微信公众号零钱提现实例
服务器的ip
//封装的关于签名的算法
$arr['sign'] = $this->makeSign($arr,$key);//签名
$var = $this->arrayToXml($arr);
// dump($arr['sign'] );exit;
$xml = $this->curl_post_ssl('https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers',$var,30);
libxml_disable_entity_loader(true);
$rdata = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
eblog('cash_xmldata',$rdata);
// dump($rdata);exit;
$return_code = trim(strtoupper($rdata['return_code']));
$result_code = trim(strtoupper($rdata['result_code']));
if ($return_code == 'SUCCESS' && $result_code == 'SUCCESS') {
$isrr = array(
'status'=>1,
'msg' => '',
);
} else {
// $returnmsg = $rdata['return_msg'];
$err_code_des = $rdata['err_code_des'];
$isrr = array(
'status' => 0,
'msg' => $err_code_des,
);
}
return $isrr;
}
protected function makesign($data,$key)
{
//获取微信支付秘钥
$data = array_filter($data);
//签名步骤一:按字典序排序参数
ksort($data);
$string_a = http_build_query($data);
$string_a = urldecode($string_a);
//签名步骤二:在string后加入KEY
//$config=$this->config;
$string_sign_temp = $string_a."&key=".$key;
//签名步骤三:MD5加密
$sign = md5($string_sign_temp);
// 签名步骤四:所有字符转为大写
$result = strtoupper($sign);
// $result = strtoupper(hash_hmac("sha256",$string_sign_temp,$key));
return $result;
}
protected function arraytoxml($data){
$str='';
foreach($data as $k=>$v) {
$str.='<'.$k.'>'.$v.''.$k.'>';
}
$str.=' ';
return $str;
}
protected function curl_post_ssl($url, $vars, $second = 30, $aHeader = array())
{
$isdir = APP_PATH."/common/library/php_sdk/lib/";//证书位置
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 终止从服务端进行验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');//证书类型
curl_setopt($ch, CURLOPT_SSLCERT, $isdir . 'apiclient_cert.pem');//证书位置
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');//CURLOPT_SSLKEY中规定的私钥的加密类型
curl_setopt($ch, CURLOPT_SSLKEY, $isdir . 'apiclient_key.pem');//证书位置
curl_setopt($ch, CURLOPT_CAINFO, 'PEM');
curl_setopt($ch, CURLOPT_CAINFO, $isdir . 'rootca.pem');
if (count($aHeader) >= 1) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
}
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部数据使用HTTP协议中的"POST"操作来发送
$data = curl_exec($ch);//执行回话
if ($data) {
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
网站题目:ThinkPHP简易微信公众号零钱提现实例
当前网址:http://pwwzsj.com/article/iiiphe.html