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.

73 lines
2.8 KiB

7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Weixin;
  3. use App\Http\Controllers\Weixin\CommonController;
  4. use Illuminate\Http\Request;
  5. class WxPayController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. //微信支付回调
  12. public function wxpayNotify(Request $request)
  13. {
  14. file_put_contents("1.txt",$GLOBALS['HTTP_RAW_POST_DATA']);
  15. //获取通知的数据
  16. $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
  17. //将XML转为array
  18. //禁止引用外部xml实体
  19. libxml_disable_entity_loader(true);
  20. $post_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  21. $get_arr = explode('&',$post_data['attach']);
  22. foreach($get_arr as $value)
  23. {
  24. $tmp_arr = explode('=',$value);
  25. $post_data[$tmp_arr[0]] = $tmp_arr[1];
  26. }
  27. if($post_data['result_code'] == 'SUCCESS')
  28. {
  29. //$post_data['out_trade_no']
  30. //$post_data['transaction_id']
  31. //$post_data['total_fee']
  32. file_put_contents("2.txt",$post_data['total_fee'].'--'.$post_data['out_trade_no'].'--'.$post_data['attach']);
  33. echo "SUCCESS";
  34. }
  35. else
  36. {
  37. echo "FAILE";
  38. }
  39. }
  40. /**
  41. * 发微信红包
  42. * @param string $openid 用户openid
  43. */
  44. public function wxhbpay($re_openid,$money,$wishing='恭喜发财,大吉大利!',$act_name='赠红包活动',$remark='赶快领取您的红包!')
  45. {
  46. //微信支付-start
  47. require_once(resource_path('org/wxpay/WxPayConfig.php')); // 导入微信配置类
  48. require_once(resource_path('org/wxpay/WxPayPubHelper.class.php')); // 导入微信支付类
  49. $wxconfig= \WxPayConfig::wxconfig();
  50. $wxHongBaoHelper = new \Sendredpack($wxconfig);
  51. $wxHongBaoHelper->setParameter("mch_billno", date('YmdHis').rand(1000, 9999));//订单号
  52. $wxHongBaoHelper->setParameter("send_name", '红包');//红包发送者名称
  53. $wxHongBaoHelper->setParameter("re_openid", $re_openid);//接受openid
  54. $wxHongBaoHelper->setParameter("total_amount", floatval($money*100));//付款金额,单位分
  55. $wxHongBaoHelper->setParameter("total_num", 1);//红包収放总人数
  56. $wxHongBaoHelper->setParameter("wishing", $wishing);//红包祝福
  57. $wxHongBaoHelper->setParameter("client_ip", '127.0.0.1');//调用接口的机器 Ip 地址
  58. $wxHongBaoHelper->setParameter("act_name", $act_name);//活劢名称
  59. $wxHongBaoHelper->setParameter("remark", $remark);//备注信息
  60. $responseXml = $wxHongBaoHelper->postXmlSSL();
  61. //用作结果调试输出
  62. //echo htmlentities($responseXml,ENT_COMPAT,'UTF-8');
  63. $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
  64. return $responseObj->result_code;
  65. }
  66. }