作者 chencheng

kaquan-1

@@ -28,9 +28,10 @@ class Wechat extends Api @@ -28,9 +28,10 @@ class Wechat extends Api
28 1.前端获取jsjdk的配置 28 1.前端获取jsjdk的配置
29 */ 29 */
30 public function get_jsjdk_config(){ 30 public function get_jsjdk_config(){
  31 + if(empty(request()->param('store_id'))){return $this->error('门店信息错误');}
31 try{ 32 try{
32 $param = request()->param(); 33 $param = request()->param();
33 - $app = WehcatModule::getInstance()->initWechat(); 34 + $app = WehcatModule::getInstance(request()->param('store_id'))->initWechat();
34 $app->jssdk->setUrl($param['url']); 35 $app->jssdk->setUrl($param['url']);
35 $APIs = ['updateAppMessageShareData','updateTimelineShareData','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone','chooseWXPay','openLocation','getLocation']; 36 $APIs = ['updateAppMessageShareData','updateTimelineShareData','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone','chooseWXPay','openLocation','getLocation'];
36 $config = $app->jssdk->buildConfig($APIs, true); 37 $config = $app->jssdk->buildConfig($APIs, true);
@@ -162,13 +163,11 @@ class Wechat extends Api @@ -162,13 +163,11 @@ class Wechat extends Api
162 163
163 public function get_user_info_by_code (){ 164 public function get_user_info_by_code (){
164 $user_id = 0; 165 $user_id = 0;
165 - if(empty(request()->param('code'))){  
166 - return $this->error('非法操作');  
167 - }  
168 - 166 + if(empty(request()->param('code'))){return $this->error('非法操作');}
  167 + if(empty(request()->param('store_id'))){return $this->error('门店信息错误');}
169 168
170 try{ 169 try{
171 - $app = WehcatModule::getInstance()->initWechat(); 170 + $app = WehcatModule::getInstance(request()->param('store_id'))->initWechat();
172 $oauth = $app->oauth; 171 $oauth = $app->oauth;
173 // 获取 OAuth 授权结果用户信息 172 // 获取 OAuth 授权结果用户信息
174 $user = $oauth->user(); 173 $user = $oauth->user();
@@ -183,6 +182,7 @@ class Wechat extends Api @@ -183,6 +182,7 @@ class Wechat extends Api
183 $save['status'] = 'normal'; 182 $save['status'] = 'normal';
184 $save['jointime'] = $save['prevtime'] = $save['logintime'] = time(); 183 $save['jointime'] = $save['prevtime'] = $save['logintime'] = time();
185 $save['loginip'] = $save['joinip'] = request()->ip(); 184 $save['loginip'] = $save['joinip'] = request()->ip();
  185 + $save['store_id'] =request()->param('store_id');
186 $w['openid'] = $openid; 186 $w['openid'] = $openid;
187 $user = Db::name('user')->where($w)->find(); 187 $user = Db::name('user')->where($w)->find();
188 //存在更新否则新增 188 //存在更新否则新增
@@ -298,16 +298,15 @@ class Wechat extends Api @@ -298,16 +298,15 @@ class Wechat extends Api
298 if(empty($my_user_id)){return $this->error('用户信息错误');} 298 if(empty($my_user_id)){return $this->error('用户信息错误');}
299 $o_w["order_no"] = $order_no; 299 $o_w["order_no"] = $order_no;
300 $order_info = Db::name('verification_order')->where($o_w)->find(); 300 $order_info = Db::name('verification_order')->where($o_w)->find();
  301 +
301 $user_id = $order_info['user_id']; 302 $user_id = $order_info['user_id'];
302 $userInfo = Db::name('user')->where(['id'=>$user_id])->find(); 303 $userInfo = Db::name('user')->where(['id'=>$user_id])->find();
303 $out_trade_no = $order_no; 304 $out_trade_no = $order_no;
304 - $o_w["order_no"] = $out_trade_no;  
305 - $order_info = Db::name('verification_order')->where($o_w)->find();  
306 $total_fee = $order_info['price'] * 100; 305 $total_fee = $order_info['price'] * 100;
307 //测试支付 306 //测试支付
308 $total_fee = mt_rand(1,10);//测试支付1分钱 307 $total_fee = mt_rand(1,10);//测试支付1分钱
309 //测试结束 308 //测试结束
310 - $app = WehcatModule::getInstance()->initWechatPay(); 309 + $app = WehcatModule::getInstance($order_info['verification_store_id'])->initWechatPay();
311 $result = $app->order->unify([ 310 $result = $app->order->unify([
312 'body' => '优惠券购买', 311 'body' => '优惠券购买',
313 'out_trade_no' => $out_trade_no, 312 'out_trade_no' => $out_trade_no,
@@ -334,7 +333,7 @@ class Wechat extends Api @@ -334,7 +333,7 @@ class Wechat extends Api
334 {"appid":"wx1c3cc5b4e2006be2","bank_type":"OTHERS","cash_fee":"10","fee_type":"CNY","is_subscribe":"Y","mch_id":"1609190540","nonce_str":"6477162663358","openid":"o5OQw6LSZr1gGhXWeYutDwjsu7UY","out_trade_no":"168552605462002","result_code":"SUCCESS","return_code":"SUCCESS","sign":"B3148E770FAEC4F6B6B0B40718D314DA","time_end":"20230531174105","total_fee":"10","trade_type":"JSAPI","transaction_id":"4200001852202305311195060106"} 333 {"appid":"wx1c3cc5b4e2006be2","bank_type":"OTHERS","cash_fee":"10","fee_type":"CNY","is_subscribe":"Y","mch_id":"1609190540","nonce_str":"6477162663358","openid":"o5OQw6LSZr1gGhXWeYutDwjsu7UY","out_trade_no":"168552605462002","result_code":"SUCCESS","return_code":"SUCCESS","sign":"B3148E770FAEC4F6B6B0B40718D314DA","time_end":"20230531174105","total_fee":"10","trade_type":"JSAPI","transaction_id":"4200001852202305311195060106"}
335 */ 334 */
336 public function notify(){ 335 public function notify(){
337 - $app = WehcatModule::getInstance()->initWechatPay(); 336 +
338 $xml = file_get_contents("php://input"); 337 $xml = file_get_contents("php://input");
339 338
340 $xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBXML_NOCDATA ));//将对象转换个JSON 339 $xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBXML_NOCDATA ));//将对象转换个JSON
@@ -537,7 +536,7 @@ class Wechat extends Api @@ -537,7 +536,7 @@ class Wechat extends Api
537 $user_info = Db::name('user')->where(['id'=>$pid])->find(); 536 $user_info = Db::name('user')->where(['id'=>$pid])->find();
538 $total_amount = $verification_store['commission'] * 100; 537 $total_amount = $verification_store['commission'] * 100;
539 //$total_amount = 100; 538 //$total_amount = 100;
540 - $app = WehcatModule::getInstance()->initWechatPay(); 539 + $app = WehcatModule::getInstance($verification_order['verification_store_id'])->initWechatPay();
541 $mch_billno=time().rand(10000,99999); 540 $mch_billno=time().rand(10000,99999);
542 $result = $app->redpack->sendNormal([ 541 $result = $app->redpack->sendNormal([
543 'mch_billno' => $mch_billno, 542 'mch_billno' => $mch_billno,
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 namespace app\server; 3 namespace app\server;
4 use EasyWeChat\Factory; 4 use EasyWeChat\Factory;
5 - 5 +use think\facade\Db;
6 6
7 /** 7 /**
8 * easyWechat 插件 8 * easyWechat 插件
@@ -14,7 +14,7 @@ class Wechat { @@ -14,7 +14,7 @@ class Wechat {
14 static public $app = null; 14 static public $app = null;
15 static private $appid= ''; 15 static private $appid= '';
16 static private $appsecret= ''; 16 static private $appsecret= '';
17 - static private $config= []; 17 +
18 static private $inc = null; 18 static private $inc = null;
19 19
20 function __construct(){ 20 function __construct(){
@@ -22,8 +22,11 @@ class Wechat { @@ -22,8 +22,11 @@ class Wechat {
22 } 22 }
23 23
24 //静态函数 24 //静态函数
25 - static public function getInstance(){ 25 + static public function getInstance($store_id){
26 if(self::$inc == null){ 26 if(self::$inc == null){
  27 + $storeInfo = Db::name('verification_store')->where(['id'=>$store_id])->find();
  28 + self::$appid = $storeInfo['appId'];
  29 + self::$appsecret = $storeInfo['appSecret'];
27 self::$inc = new self(); 30 self::$inc = new self();
28 } 31 }
29 return self::$inc; 32 return self::$inc;
@@ -31,8 +34,8 @@ class Wechat { @@ -31,8 +34,8 @@ class Wechat {
31 34
32 //初始化 easywechat app 35 //初始化 easywechat app
33 static public function initWechat(){ 36 static public function initWechat(){
34 - $appid= config("site.appid");  
35 - $appsecret= config("site.appsecret"); 37 + $appid= self::$appid;
  38 + $appsecret= self::$appsecret;
36 //easyWechat配置 39 //easyWechat配置
37 $config = [ 40 $config = [
38 'app_id' => $appid, 41 'app_id' => $appid,
@@ -47,7 +50,7 @@ class Wechat { @@ -47,7 +50,7 @@ class Wechat {
47 //初始化 jssdk支付 50 //初始化 jssdk支付
48 static public function initWechatPay(){ 51 static public function initWechatPay(){
49 //测试公众号 52 //测试公众号
50 - $appid= config("site.appid"); 53 + $appid= self::$appid;
51 $mch_id = config("site.pay_mch_id"); 54 $mch_id = config("site.pay_mch_id");
52 $pay_key = config("site.pay_key");; 55 $pay_key = config("site.pay_key");;
53 $notify_url = 'https://coupon.xp.yn.cn'.url('/api/v1/wechat/notify'); 56 $notify_url = 'https://coupon.xp.yn.cn'.url('/api/v1/wechat/notify');