You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.8 KiB

6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Weixin;
  3. use Illuminate\Http\Request;
  4. use DB;
  5. use Log;
  6. class WxPayController extends CommonController
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. /**
  13. * 发微信红包
  14. * @param string $openid 用户openid
  15. */
  16. public function wxhbpay($re_openid,$money,$wishing='恭喜发财,大吉大利!',$act_name='赠红包活动',$remark='赶快领取您的红包!')
  17. {
  18. //微信支付-start
  19. require_once(resource_path('org/wxpay/WxPayConfig.php')); // 导入微信配置类
  20. require_once(resource_path('org/wxpay/WxPayPubHelper.class.php')); // 导入微信支付类
  21. $wxconfig= \WxPayConfig::wxconfig();
  22. $wxHongBaoHelper = new \Sendredpack($wxconfig);
  23. $wxHongBaoHelper->setParameter("mch_billno", date('YmdHis').rand(1000, 9999));//订单号
  24. $wxHongBaoHelper->setParameter("send_name", '红包');//红包发送者名称
  25. $wxHongBaoHelper->setParameter("re_openid", $re_openid);//接受openid
  26. $wxHongBaoHelper->setParameter("total_amount", floatval($money*100));//付款金额,单位分
  27. $wxHongBaoHelper->setParameter("total_num", 1);//红包収放总人数
  28. $wxHongBaoHelper->setParameter("wishing", $wishing);//红包祝福
  29. $wxHongBaoHelper->setParameter("client_ip", '127.0.0.1');//调用接口的机器 Ip 地址
  30. $wxHongBaoHelper->setParameter("act_name", $act_name);//活劢名称
  31. $wxHongBaoHelper->setParameter("remark", $remark);//备注信息
  32. $responseXml = $wxHongBaoHelper->postXmlSSL();
  33. //用作结果调试输出
  34. //echo htmlentities($responseXml,ENT_COMPAT,'UTF-8');
  35. $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
  36. return $responseObj->result_code;
  37. }
  38. }