diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php
index 72f331a..bc111ce 100644
--- a/app/Http/Controllers/Weixin/UserController.php
+++ b/app/Http/Controllers/Weixin/UserController.php
@@ -78,9 +78,10 @@ class UserController extends CommonController
require_once(resource_path('org/wxpay/WxPayConfig.php')); // 导入微信配置类
require_once(resource_path('org/wxpay/WxPayPubHelper.class.php')); // 导入微信支付类
- $body = '商品购买';//订单详情
- $out_trade_no = '2017787878';//订单号
+ $body = '充值';//订单详情
+ $out_trade_no = '20177878738';//订单号
$total_fee = floatval(0.01*100);//价格0.01
+ $attach = 'pay_type=1';
$notify_url = route('weixin_wxpay_notify');//通知地址
$wxconfig= \WxPayConfig::wxconfig();
@@ -101,10 +102,10 @@ class UserController extends CommonController
$unifiedOrder->setParameter("body","$body");//商品描述
$unifiedOrder->setParameter("out_trade_no","$out_trade_no");//商户订单号
$unifiedOrder->setParameter("total_fee","$total_fee");//总金额
- $unifiedOrder->setParameter("notify_url","$notify_url");//通知地址
+ //$unifiedOrder->setParameter("attach","$attach"); //附加数据,选填,在查询API和支付通知中原样返回,可作为自定义参数使用,示例:a=1&b=2
+ $unifiedOrder->setParameter("notify_url","$notify_url");//通知地址
$unifiedOrder->setParameter("trade_type","JSAPI");//交易类型
- //$unifiedOrder->setParameter("attach","test"); //附加数据,选填,在查询API和支付通知中原样返回,可作为自定义参数使用
- $prepay_id = $unifiedOrder->getPrepayId();
+ $prepay_id = $unifiedOrder->getPrepayId();
//=========步骤3:使用jsapi调起支付============
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
diff --git a/app/Http/Controllers/Weixin/WxPayController.php b/app/Http/Controllers/Weixin/WxPayController.php
index a102b09..e23d591 100644
--- a/app/Http/Controllers/Weixin/WxPayController.php
+++ b/app/Http/Controllers/Weixin/WxPayController.php
@@ -14,8 +14,61 @@ class WxPayController extends CommonController
//微信支付回调
public function wxpayNotify(Request $request)
{
- require_once(resource_path('org/wxpay/WxPayPubHelper.class.php'));
+ file_put_contents("1.txt",$GLOBALS['HTTP_RAW_POST_DATA']);
+ //获取通知的数据
+ $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
+ //将XML转为array
+ //禁止引用外部xml实体
+ libxml_disable_entity_loader(true);
+ $post_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
+ $get_arr = explode('&',$post_data['attach']);
+ foreach($get_arr as $value)
+ {
+ $tmp_arr = explode('=',$value);
+ $post_data[$tmp_arr[0]] = $tmp_arr[1];
+ }
- return view('weixin.cart.index', $data);
+ if($post_data['result_code'] == 'SUCCESS')
+ {
+ //$post_data['out_trade_no']
+ //$post_data['transaction_id']
+ //$post_data['total_fee']
+ file_put_contents("2.txt",$post_data['total_fee'].'--'.$post_data['out_trade_no'].'--'.$post_data['attach']);
+ echo "SUCCESS";
+ }
+ else
+ {
+ echo "FAILE";
+ }
}
+
+ /**
+ * 发微信红包
+ * @param string $openid 用户openid
+ */
+ public function wxhbpay($re_openid,$money,$wishing='恭喜发财,大吉大利!',$act_name='赠红包活动',$remark='赶快领取您的红包!')
+ {
+ //微信支付-start
+ require_once(resource_path('org/wxpay/WxPayConfig.php')); // 导入微信配置类
+ require_once(resource_path('org/wxpay/WxPayPubHelper.class.php')); // 导入微信支付类
+
+ $wxconfig= \WxPayConfig::wxconfig();
+ $wxHongBaoHelper = new \Sendredpack($wxconfig);
+ $wxHongBaoHelper->setParameter("mch_billno", date('YmdHis').rand(1000, 9999));//订单号
+ $wxHongBaoHelper->setParameter("send_name", '红包');//红包发送者名称
+ $wxHongBaoHelper->setParameter("re_openid", $re_openid);//接受openid
+ $wxHongBaoHelper->setParameter("total_amount", floatval($money*100));//付款金额,单位分
+ $wxHongBaoHelper->setParameter("total_num", 1);//红包収放总人数
+ $wxHongBaoHelper->setParameter("wishing", $wishing);//红包祝福
+ $wxHongBaoHelper->setParameter("client_ip", '127.0.0.1');//调用接口的机器 Ip 地址
+ $wxHongBaoHelper->setParameter("act_name", $act_name);//活劢名称
+ $wxHongBaoHelper->setParameter("remark", $remark);//备注信息
+ $responseXml = $wxHongBaoHelper->postXmlSSL();
+ //用作结果调试输出
+ //echo htmlentities($responseXml,ENT_COMPAT,'UTF-8');
+ $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
+ return $responseObj->result_code;
+ }
+
+
}
\ No newline at end of file
diff --git a/resources/org/wxpay/WxPayConfig.php b/resources/org/wxpay/WxPayConfig.php
index d5910f0..b344361 100644
--- a/resources/org/wxpay/WxPayConfig.php
+++ b/resources/org/wxpay/WxPayConfig.php
@@ -61,22 +61,26 @@ class WxPayConfig
{
//=======【基本信息设置】=====================================
//微信公众号身份的唯一标识。审核通过后,在微信发送的邮件中查看
- $wxconfig['APPID'] = self::APPID;
+ $wxconfig['APPID'] = self::APPID;
//受理商ID,身份标识
- $wxconfig['MCHID'] = self::MCHID;
+ $wxconfig['MCHID'] = self::MCHID;
//商户支付密钥Key。审核通过后,在微信发送的邮件中查看
- $wxconfig['KEY'] = self::KEY;
+ $wxconfig['KEY'] = self::KEY;
//JSAPI接口中获取openid,审核后在公众平台开启开发模式后可查看
- $wxconfig['APPSECRET'] = self::APPSECRET;
+ $wxconfig['APPSECRET'] = self::APPSECRET;
+
+ //=======【JSAPI路径设置】===================================
+ //获取access_token过程中的跳转uri,通过跳转将code传入jsapi支付页面
+ $wxconfig['JS_API_CALL_URL'] = '';
//=======【证书路径设置】=====================================
//证书路径,注意应该填写绝对路径
- $wxconfig['SSLCERT_PATH'] = self::SSLCERT_PATH;
- $wxconfig['SSLKEY_PATH'] = self::SSLKEY_PATH;
+ $wxconfig['SSLCERT_PATH'] = self::SSLCERT_PATH;
+ $wxconfig['SSLKEY_PATH'] = self::SSLKEY_PATH;
//=======【异步通知url设置】===================================
//异步通知url,商户根据实际开发过程设定
- //$wxconfig['NOTIFY_URL'] = 'http://'.$_SERVER['HTTP_HOST'].U('Wxpay/notify_url'); //放在下单时,添加
+ $wxconfig['NOTIFY_URL'] = ''; //放在下单时,添加
//=======【curl超时设置】===================================
//本例程通过curl使用HTTP POST方法,此处可修改其超时时间,默认为30秒
diff --git a/resources/org/wxpay/WxPayPubHelper.class.php b/resources/org/wxpay/WxPayPubHelper.class.php
index 0322cb7..bf02c9b 100644
--- a/resources/org/wxpay/WxPayPubHelper.class.php
+++ b/resources/org/wxpay/WxPayPubHelper.class.php
@@ -166,7 +166,7 @@ class Common_util_pub
//初始化curl
$ch = curl_init();
//设置超时
- curl_setopt($ch, CURLOP_TIMEOUT, $second);
+ curl_setopt($ch, CURLOPT_TIMEOUT, $second);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
@@ -186,7 +186,6 @@ class Common_util_pub
//返回结果
if($data)
{
- curl_close($ch);
return $data;
}
else
@@ -194,7 +193,6 @@ class Common_util_pub
$error = curl_errno($ch);
echo "curl出错,错误码:$error"."
";
echo "错误原因查询";
- curl_close($ch);
return false;
}
}
@@ -379,7 +377,6 @@ class UnifiedOrder_pub extends Wxpay_client_pub
return $prepay_id;
}
-
}
/**
@@ -826,7 +823,7 @@ class JsApi_pub extends Common_util_pub
//初始化curl
$ch = curl_init();
//设置超时
- curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);
+ curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
diff --git a/resources/views/weixin/user/userRechargeOrderDetail.blade.php b/resources/views/weixin/user/userRechargeOrderDetail.blade.php
index 3c7c206..0b808e4 100644
--- a/resources/views/weixin/user/userRechargeOrderDetail.blade.php
+++ b/resources/views/weixin/user/userRechargeOrderDetail.blade.php
@@ -3,19 +3,18 @@
-