Ejemplo n.º 1
0
require_once "./lib/WxPay.RedPack.php";
require_once "./lib/WxPay.RedPack.Api.php";
$openid = 'o9WpmxEqZMZNtjHEoN8vuuFHb12I';
//kangyu
$act_name = '活动名称';
//活动名称,少于32字符
$wishing = '祝福语';
//祝福语
$send_name = '活动方名称';
//发放红包的活动方名称,少于32字符
$remark = '微信支付开发测试';
//备注
// $money = 2.56;//单位:元
$money = mt_rand(100, 500);
//单位 分
$input = new WxPayRedPack();
//创建微信红包输入对象
$input->SetRe_openid($openid);
//设置openid
$input->SetTotal_num();
//设置默认total_num=1
$input->SetAct_name($act_name);
//设置活动名称
$input->SetWishing($wishing);
//设置祝福语
$input->SetSend_name($send_name);
//设置活动方名称
$input->SetRemark($remark);
//设置备注
$input->SetTotal_amount($money);
//设置发送红包钱数,单位分
Ejemplo n.º 2
0
 /**
  * [微信支付红包类]
  * @param  WxPayRedPack  $inputObj [微信红包输入对象]
  * @param  integer $timeOut  [description]
  * @return [type]            [description]
  */
 public static function sendRedpack($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
     //检测必填参数
     if (!$inputObj->IsRe_openidSet()) {
         throw new WxPayException("缺少企业付款支付接口必填参数re_openid!");
     } else {
         if (!$inputObj->IsTotal_amountSet()) {
             throw new WxPayException("缺少企业付款支付接口必填参数total_amount!");
         } else {
             if (!$inputObj->IsTotal_numSet()) {
                 throw new WxPayException("缺少企业付款支付接口必填参数total_num!");
             } else {
                 if (!$inputObj->IsSend_nameSet()) {
                     throw new WxPayException("缺少企业付款支付接口必填参数send_name!");
                 } else {
                     if (!$inputObj->IsWishingSet()) {
                         throw new WxPayException("缺少企业付款支付接口必填参数wishing!");
                     } else {
                         if (!$inputObj->IsAct_nameSet()) {
                             throw new WxPayException("缺少企业付款支付接口必填参数act_name!");
                         } else {
                             if (!$inputObj->IsRemarkSet()) {
                                 throw new WxPayException("缺少企业付款支付接口必填参数remark!");
                             }
                         }
                     }
                 }
             }
         }
     }
     //异步通知url未设置,则使用配置文件中的url
     // if(!$inputObj->IsNotify_urlSet()){
     // 	$inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL);//异步通知url
     // }
     $inputObj->SetWxappid(WxPayConfig::APPID);
     //公众账号ID
     $inputObj->SetMch_id(WxPayConfig::MCHID);
     //商户号
     $inputObj->SetClient_ip($_SERVER['REMOTE_ADDR']);
     //终端ip
     //$inputObj->SetSpbill_create_ip("1.1.1.1");
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     // $inputObj->SetPartner_trade_no(WxPayConfig::MCHID.date("YmdHis").mt_rand(1000,9999));//生成商户订单号
     $inputObj->SetMch_billno(WxPayConfig::MCHID . date("YmdHis") . substr(microtime(), 2, 4));
     //生成商户订单号
     //签名,必须坐在所有待传参数都设置完毕才可以进行签名
     $inputObj->SetSign();
     $xml = $inputObj->ToXml();
     $response = self::postXmlCurl($xml, $url, true, $timeOut);
     // $result = WxPayResults::Init($response);
     // self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
     $result = $inputObj->FromXml($response);
     return $result;
 }