PHP微信红包生成代码分享(4)

class Wxapi { private $app_id = 'wxXXXXXXXXXXXX'; //公众账号appid,首先申请与之配套的公众账号 private $app_secret = 'XXXXXXXXXXXXXXXXXXXXXXXX';//公众号secret,用户获取用户授权token private $app_mchid = 'XXXXXXXX';//商户号id function __construct(){ //do sth here.... } /** * 微信支付 * @param string $openid 用户openid */ public function pay($re_openid) { include_once('WxHongBaoHelper.php'); $commonUtil = new CommonUtil(); $wxHongBaoHelper = new WxHongBaoHelper(); $wxHongBaoHelper->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; }

获取随机字符串方法:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e62d370074f91a95783baecc4d9c9052.html