PHP微信红包API接口
发布时间:2020-12-12 21:11:44 所属栏目:PHP教程 来源:网络整理
导读:p style="text-align: left"首先给大家看一看这个表格: p style="text-align: center" 根据微信高级红包接口,开发PHP版本的API接口,现在进行主要代码分析。 红包接口调用请求代码,所有请求参数为必填参数与文档对应: setParameter("nonce_str",$this->g
<p style="text-align: left">首先给大家看一看这个表格: <p style="text-align: center"> 根据微信高级红包接口,开发PHP版本的API接口,现在进行主要代码分析。 红包接口调用请求代码,所有请求参数为必填参数与文档对应: setParameter("nonce_str",$this->great_rand());//随机字符串,丌长于 32 位
$wxHongBaoHelper->setParameter("mch_billno",$this->app_mchid.date('YmdHis').rand(1000,9999));//订单号
$wxHongBaoHelper->setParameter("mch_id",$this->app_mchid);//商户号
$wxHongBaoHelper->setParameter("wxappid",$this->app_id);
$wxHongBaoHelper->setParameter("nick_name",'红包');//提供方名称
$wxHongBaoHelper->setParameter("send_name",'红包');//红包发送者名称
$wxHongBaoHelper->setParameter("re_openid",$re_openid);//相对于医脉互通的openid
$wxHongBaoHelper->setParameter("total_amount",100);//付款金额,单位分
$wxHongBaoHelper->setParameter("min_value",100);//最小红包金额,单位分
$wxHongBaoHelper->setParameter("max_value",100);//最大红包金额,单位分
$wxHongBaoHelper->setParameter("total_num",1);//红包収放总人数
$wxHongBaoHelper->setParameter("wishing",'感谢您参与红包派发活动,祝您新年快乐!');//红包祝福诧
$wxHongBaoHelper->setParameter("client_ip",'127.0.0.1');//调用接口的机器 Ip 地址
$wxHongBaoHelper->setParameter("act_name",'红包活动');//活劢名称
$wxHongBaoHelper->setParameter("remark",'快来抢!');//备注信息
$postXml = $wxHongBaoHelper->create_hongbao_xml();
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
$responseXml = $wxHongBaoHelper->curl_post_ssl($url,$postXml);
//用作结果调试输出
//echo htmlentities($responseXml,ENT_COMPAT,'UTF-8');
$responSEObj = simplexml_load_string($responseXml,'SimpleXMLElement',LIBXML_NOCDATA);
return $responSEObj->return_code;
}
获取随机字符串方法:
");
}
if($this->check_sign_parameters() == false) { //检查生成签名参数
throw new SDKRuntimeException("生成签名参数缺失!" . "
"); } $commonUtil = new CommonUtil(); ksort($this->parameters); $unSignParaString = $commonUtil->formatQueryParaMap($this->parameters,false); $md5SignUtil = new MD5SignUtil(); return $md5SignUtil->sign($unSignParaString,$commonUtil->trimString(PARTNERKEY)); }catch (SDKRuntimeException $e) { die($e->errorMessage()); } } CURL请求以及发送证书:= 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:$errorn";
curl_close($ch);
return false;
}
}
入口文件:_route('userinfo',$param);
if(empty($userinfo['openid'])){
exit("NOAUTH");
}
//调取支付方法
$packet->_route('wxpacket',array('openid'=>$userinfo['openid']));
}else{
$packet->_route('userinfo');
}
以上就是关于PHP微信红包API接口的详细代码,分享给大家,希望对大家的学习有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |