sendRedpack( )微信现金红包函数 * * * * * >[warning] 详细使用方法,RhaPHP官方有提供红包插件应用。 ~~~ /** * 现金红包 * 微信规定红包最小金额为1元 * 本函数输参数金额为元 * @param string $mid * @param array $param * @return array */ function sendRedpack($mid = '', $param = [], $addon = '') { if (setWxpayConfig($mid)) { $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; echo $order_number = time() . rand_string(18, 1); $redpackObj = new Redpack(); $redpackObj->setParments("re_openid", isset($param['openid']) ? $param['openid'] : '');//openid $redpackObj->setParments("mch_billno", $order_number);//订单号 $redpackObj->setParments("nick_name", isset($param['nick_name']) ? $param['nick_name'] : '有钱任性');//提供方名称|必填 $redpackObj->setParments("send_name", isset($param['send_name']) ? $param['send_name'] : '有钱的二狗子');//红包发送者名称|必填 $redpackObj->setParments("total_amount", isset($param['money']) ? $param['money'] * 100 : '');//付款金额,单位:元、元、元、|必填 $redpackObj->setParments("min_value", isset($param['min_value']) ? $param['min_value'] : '100');//最小红包金额,单位分 $redpackObj->setParments("max_value", isset($param['max_value']) ? $param['max_value'] : '100');//最大红包金额,单位分 $redpackObj->setParments("total_num", isset($param['total_num']) ? $param['total_num'] : '1');//红包収放总人数 $redpackObj->setParments("wishing", isset($param['wishing']) ? $param['wishing'] : '恭喜发财');//红包祝福诧 $redpackObj->setParments("client_ip", \think\Request::instance()->ip());//调用接口的机器 Ip 地址 $redpackObj->setParments("act_name", isset($param['act_name']) ? $param['act_name'] : '红包活动');//活动名称 $redpackObj->setParments("remark", isset($param['remark']) ? $param['remark'] : '红包活动');//备注信息 $redpackObj->setParments("nonce_str", getRandChar(32));//备注信息 $xml = $redpackObj->createRedpackXml(); $result = $redpackObj->xmlToArray($redpackObj->postXmlCurl($xml, $url, true)); $sslcert = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_cert.pem'; $sslkey = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_key.pem'; if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') { unlink($sslcert); unlink($sslkey); $model = new \app\common\model\Redpack(); $param['order_number'] = $order_number; $param['mpid'] = $mid; $param['create_time'] = time(); $param['addon'] = $addon; $model->allowField(true)->save($param); $param['errCode'] = 0; $param['errMsg'] = '发放成功'; return $param; } else { unlink($sslcert); unlink($sslkey); return ['errCode' => -1, 'errMsg' => 'errMsg:' . $result['result_code'] . ':' . $result['return_msg']]; } }else{ return ['errCode' => -1, 'errMsg' => 'errMsg:该公众号还没有配置支付相关的参数']; } } ~~~