配置商户平台,手头没账号了,,就不记录了,
拿下证书,WxHongBaoHelper 在 这里面配置好路径,
public function fhb($money,$openid,$uid){
//发红包
//include_once ('./WeixinRedPacket/WxHongBaoHelper.php');
//加载 第三方类库 . 基础目录
vendor('WeixinRedPacket.WxHongBaoHelper');
// 微信 OpenID
$re_openid = $openid;//获取openid
//红包金额单位是分所以得乘以100
$hmoney=$money;//要发放的金额
$price = $hmoney*100;//测试时设为1元 微信分位支付, app是元位,但是app回调又是分位 = =
// $price = 100;
//组装数据 发往微信
$wxHongBaoHelper = new \WxHongBaoHelper ();
//无 设备号, 文档非必填
$wxHongBaoHelper->setParameter ( "nonce_str", $this->great_rand () ); //随机字符串,丌长于 32 位
$wxHongBaoHelper->setParameter ( "partner_trade_no", $this->app_mchid . date ( 'YmdHis' ) . rand ( 1000, 9999 ) ); //订单号
$wxHongBaoHelper->setParameter ( "mchid", $this->app_mchid ); //商户号
$wxHongBaoHelper->setParameter ( "mch_appid", $this->app_id );//相对于平台的openid 申请商户号的appid或商户号绑定的appid
// $wxHongBaoHelper->setParameter ( "nick_name", '弘康电子科技' ); //提供方名称
// $wxHongBaoHelper->setParameter ( "send_name", '弘康电子科技' ); //红包发送者名称
$wxHongBaoHelper->setParameter ( "openid", $re_openid ); //商户appid下,某用户的openid
$wxHongBaoHelper->setParameter ( "amount", $price ); //付款金额,单位分
// $wxHongBaoHelper->setParameter ( "min_value", 1 ); //最小红包金额,单位分
// $wxHongBaoHelper->setParameter ( "max_value", 20000 ); //最大红包金额,单位分
// $wxHongBaoHelper->setParameter ( "total_num", 1 ); //红包収放总人数
// $wxHongBaoHelper->setParameter ( "wishing", '提现申请' ); //红包祝福诧
$wxHongBaoHelper->setParameter ( "spbill_create_ip", '139.196.4.212' ); //调用接口的机器 Ip 地址
// $wxHongBaoHelper->setParameter ( "act_name", '提现申请' ); //活劢名称
$wxHongBaoHelper->setParameter ( "desc", '奖励提现' ); //备注信息
$wxHongBaoHelper->setParameter ( "check_name", 'NO_CHECK' ); //NO_CHECK:不校验真实姓名 FORCE_CHECK:强校验真实姓名
//生成xml并且生成签名
$postXml = $wxHongBaoHelper->create_hongbao_xml ( $this->api_key );
//提交请求 红包接口 和转账 接口 换下就行,微信官方文档
// $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
$responseXml = $wxHongBaoHelper->curl_post_ssl ( $url, $postXml );
$responseObj = simplexml_load_string ( $responseXml, 'SimpleXMLElement', LIBXML_NOCDATA );
// dump ( $responseObj );die;
//转换成数组
$responseArr = ( array ) $responseObj;
// dump($responseArr);die;
$return_code = $responseArr ['return_code'];
$result_code = $responseArr ['result_code'];
//判断是否红包是否发送成功
if ($return_code == "SUCCESS" && $result_code == "SUCCESS") {
$oco_member = M('getmoney');
$save['is_send']="2";
$where['id']=$uid;
$rel=$oco_member->where($where)->save($save);
if($rel){
echo "<script>alert('审核成功!');window.location.href='getmoneylist';</script>";
}else{
echo "<script>alert('审核失败!');window.location.href='getmoneylist';</script>";
}
}else{
$this->error($responseArr['return_msg'],U('User/getmoneylist'));
}
}
//获取随机数
public function great_rand() {
$str = '1234567890abcdefghijklmnopqrstuvwxyz';
for($i = 0; $i < 30; $i ++) {
$j = rand ( 0, 35 );
$t1 .= $str [$j];
}
return $t1;
}
rootca.pem 这个证书文件, 已经不用了
网友评论