微信红包功能我相信各位朋友都知道吧,但如果我们要把红包集成到网站那么要如何来做呢?下面小编就来为各位分享一个php 微信发红包接口测试实例,希望文章能够帮助到各位朋友
下面是一个类。使用方法:
$arr['openid']='ojgttt8of9vdycgsjmachpa-jy1u';
$arr['hbname']=提现申请;
$arr['body']=您的提现申请已经成功;
$arr['fee']=1;
$comm = new common_util_pub();
$re = $comm->sendhongbaoto($arr);
var_dump($re);
注意证书位置和 商户后台设置的key需要修改。
$v)
{
if($urlencode)
{
$v = urlencode($v);
}
//$buff .= strtolower($k) . = . $v . &;
$buff .= $k . = . $v . &;
}
$reqpar;
if (strlen($buff) > 0)
{
$reqpar = substr($buff, 0, strlen($buff)-1);
}
return $reqpar;
}
/**
* 作用:生成签名
*/
public function getsign($obj)
{
foreach ($obj as $k => $v)
{
$parameters[$k] = $v;
}
//签名步骤一:按字典序排序参数
ksort($parameters);
$string = $this->formatbizqueryparamap($parameters, false);
//echo '【string1】'.$string.'';
//签名步骤二:在string后加入key
$string = $string.&key=.254554sefg4exxxxxxxxs5cds1; // 商户后台设置的key
//echo 【string2】.$string.;
//签名步骤三:md5加密
$string = md5($string);
//echo 【string3】 .$string.;
//签名步骤四:所有字符转为大写
$result_ = strtoupper($string);
//echo 【result】 .$result_.;
return $result_;
}
/**
* 作用:array转xml
*/
public function arraytoxml($arr)
{
$xml = ;
foreach ($arr as $key=>$val)
{
if (is_numeric($val))
{
$xml.=.$val..$key.>;
}
else
$xml.=.$key.>;
}
$xml.=;
return $xml;
}
/**
* 作用:将xml转为array
*/
public function xmltoarray($xml)
{
//将xml转为array
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'simplexmlelement', libxml_nocdata)), true);
return $array_data;
}
public function wxhttpsrequestpem( $vars,$url, $second=30,$aheader=array()){
$ch = curl_init();
//超时时间
curl_setopt($ch,curlopt_timeout,$second);
curl_setopt($ch,curlopt_returntransfer, 1);
//这里设置代理,如果有的话
//curl_setopt($ch,curlopt_proxy, '10.206.30.98');
//curl_setopt($ch,curlopt_proxyport, 8080);
curl_setopt($ch,curlopt_url,$url);
curl_setopt($ch,curlopt_ssl_verifypeer,false);
curl_setopt($ch,curlopt_ssl_verifyhost,false);
//以下两种方式需选择一种
//第一种方法,cert 与 key 分别属于两个.pem文件
//默认格式为pem,可以注释
curl_setopt($ch,curlopt_sslcerttype,'pem');
curl_setopt($ch,curlopt_sslcert,dirname(__file__).'/hongbao/apiclient_cert.pem');
//默认格式为pem,可以注释
curl_setopt($ch,curlopt_sslkeytype,'pem');
curl_setopt($ch,curlopt_sslkey,dirname(__file__).'/hongbao/apiclient_key.pem');
curl_setopt($ch,curlopt_cainfo,'pem');
curl_setopt($ch,curlopt_cainfo,dirname(__file__).'/hongbao/rootca.pem');
//第二种方式,两个文件合成一个.pem文件
//curl_setopt($ch,curlopt_sslcert,getcwd().'/all.pem');
if( count($aheader) >= 1 ){
curl_setopt($ch, curlopt_httpheader, $aheader);
}
curl_setopt($ch,curlopt_post, 1);
curl_setopt($ch,curlopt_postfields,$vars);
$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;
}
}
}
?>