|
/**
- 发送红包
- @param string $openid 用户在该公众号下的Openid
- @param float $totalFee 红包金额 单位元
- @param string $outTradeNo 订单号
- @param string $orderName 红包发送者名称
- @param string $wishing 祝福语
- @param string $actName 互动名称
- @return string
/
public function createJsBizPackage($openid,$totalFee,$actName)
{
$config = array(
'mch_id' => $this->mchid,'appid' => $this->appid,'key' => $this->apiKey,);
$unified = array(
'wxappid' => $config['appid'],'send_name' => $sendName,'mch_id' => $config['mch_id'],'nonce_str' => self::createNonceStr(),'re_openid' => $openid,'mch_billno' => $outTradeNo,'client_ip' => '127.0.0.1','total_amount' => intval($totalFee 100),//单位 转为分
'total_num'=>1,//红包发放总人数
'wishing'=>$wishing,//红包祝福语
'act_name'=>$actName,//活动名称
'remark'=>'remark',//备注信息,如为中文注意转为UTF8编码
'scene_id'=>'PRODUCT_2',//发放红包使用场景,红包金额大于200时必传。https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
);
$unified['sign'] = self::getSign($unified,$config['key']);
$responseXml = $this->curlPost('https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack',self::arrayToXml($unified));
$unifiedOrder = simplexml_load_string($responseXml,'SimpleXMLElement',LIBXML_NOCDATA);
if ($unifiedOrder === false) {
die('parse xml error');
}
if ($unifiedOrder->return_code != 'SUCCESS') {
die($unifiedOrder->return_msg);
}
if ($unifiedOrder->result_code != 'SUCCESS') {
die($unifiedOrder->err_code);
}
return true;
}
public static function curlGet($url = '',$options = array())
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TIMEOUT,30);
if (!empty($options)) {
curl_setopt_array($ch,$options);
}
//https请求 不验证证书和host
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function curlPost($url = '',$postData = '',$options = array())
{
if (is_array($postData)) {
$postData = http_build_query($postData);
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,CURLOPT_POSTFIELDS,$postData);
curl_setopt($ch,30); //设置cURL允许执行的最长秒数
if (!empty($options)) {
curl_setopt_array($ch,false);
(编辑:网站开发网_马鞍山站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|