作者 郭鑫

退款功能,后台功能调试

@@ -62,6 +62,52 @@ class AlipayController extends NotifyCommonController @@ -62,6 +62,52 @@ class AlipayController extends NotifyCommonController
62 var_dump($response); 62 var_dump($response);
63 } 63 }
64 64
  65 + // 退款
  66 + public function refund($data) {
  67 +// $data = $this->request->param();
  68 + $config = $this->config;
  69 +
  70 + //商户订单号,商户网站订单系统中唯一订单号
  71 + $out_trade_no = '';
  72 + if(!empty($data['out_trade_no'])) {
  73 + $out_trade_no = trim($data['out_trade_no']);
  74 + }
  75 +
  76 + //支付宝交易号
  77 + if(!empty($data['trade_no'])) {
  78 + $trade_no = trim($data['trade_no']);
  79 + }
  80 + //请二选一设置
  81 +
  82 + //需要退款的金额,该金额不能大于订单金额,必填
  83 + $refund_amount = trim($data['refund_amount']);
  84 +
  85 + //退款的原因说明
  86 + $refund_reason = trim($data['refund_reason']);
  87 +
  88 + //标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传
  89 +// $out_request_no = trim($data['WIDTRout_request_no']);
  90 + $out_request_no = '';
  91 +
  92 + //构造参数
  93 + $RequestBuilder=new \AlipayTradeRefundContentBuilder();
  94 + $RequestBuilder->setOutTradeNo($out_trade_no);
  95 + $RequestBuilder->setTradeNo($trade_no);
  96 + $RequestBuilder->setRefundAmount($refund_amount);
  97 + $RequestBuilder->setOutRequestNo($out_request_no);
  98 + $RequestBuilder->setRefundReason($refund_reason);
  99 +
  100 + $aop = new \AlipayTradeService($config);
  101 +
  102 + /**
  103 + * alipay.trade.refund (统一收单交易退款接口)
  104 + * @param $builder 业务参数,使用buildmodel中的对象生成。
  105 + * @return $response 支付宝返回的信息
  106 + */
  107 + $response = $aop->Refund($RequestBuilder);
  108 + return $response;
  109 + }
  110 +
65 // 回调 111 // 回调
66 public function notify_url() { 112 public function notify_url() {
67 $config = $this->config; 113 $config = $this->config;
@@ -12,6 +12,7 @@ use api\portal\model\AgencyModel; @@ -12,6 +12,7 @@ use api\portal\model\AgencyModel;
12 use api\portal\model\MemberModel; 12 use api\portal\model\MemberModel;
13 use api\portal\model\MoneyDetailModel; 13 use api\portal\model\MoneyDetailModel;
14 use api\portal\model\OrderModel; 14 use api\portal\model\OrderModel;
  15 +use api\portal\model\RewardModel;
15 use api\portal\model\UserNeedModel; 16 use api\portal\model\UserNeedModel;
16 use cmf\controller\HomeBaseController; 17 use cmf\controller\HomeBaseController;
17 use think\Db; 18 use think\Db;
@@ -30,7 +31,7 @@ class NotifyCommonController extends HomeBaseController @@ -30,7 +31,7 @@ class NotifyCommonController extends HomeBaseController
30 $order_model = new OrderModel(); 31 $order_model = new OrderModel();
31 $orderInfo = $order_model->where($where)->find(); 32 $orderInfo = $order_model->where($where)->find();
32 if($orderInfo['status'] == 1) { 33 if($orderInfo['status'] == 1) {
33 -// $order_model->startTrans(); 34 + $order_model->startTrans();
34 $update = [ 35 $update = [
35 'status' => 2, 36 'status' => 2,
36 'pay_type' => $pay_type, 37 'pay_type' => $pay_type,
@@ -71,6 +72,12 @@ class NotifyCommonController extends HomeBaseController @@ -71,6 +72,12 @@ class NotifyCommonController extends HomeBaseController
71 if($orderInfo['type'] == 1) { 72 if($orderInfo['type'] == 1) {
72 $order_type = 1; 73 $order_type = 1;
73 } 74 }
  75 + if($orderInfo['type'] == 2) {
  76 + $order_type = 2;
  77 + }
  78 + if($orderInfo['type'] == 3) {
  79 + $order_type = 3;
  80 + }
74 $insert = [ 81 $insert = [
75 'order_id' => $orderInfo['id'], 82 'order_id' => $orderInfo['id'],
76 'user_id' => $user['id'], 83 'user_id' => $user['id'],
@@ -87,8 +94,36 @@ class NotifyCommonController extends HomeBaseController @@ -87,8 +94,36 @@ class NotifyCommonController extends HomeBaseController
87 $order_model->rollback(); 94 $order_model->rollback();
88 return false; 95 return false;
89 } 96 }
  97 + // 增加用户推荐人余额
  98 + if($user['referee_id'] && ($orderInfo['type'] == 1 || $orderInfo['type'] == 2)) {
  99 + $referee_user = $member_model->where(['id'=>$user['referee_id']])->find();
  100 + if($referee_user) {
  101 + $reward_model = new RewardModel();
  102 + $reward_number = $reward_model->where(['type'=>5,'status'=>['neq',9]])->value('number');
  103 + $referee_result = $member_model->where(['id'=>$user['referee_id']])->setInc('money',$reward_number);
  104 + if(!$referee_result) {
  105 + $order_model->rollback();
  106 + return false;
  107 + }
  108 + $insert = [
  109 + 'user_id' => $user['id'],
  110 + 'user_type' => $user['type'],
  111 + 'title' => '推荐人奖励',
  112 + 'money' => $reward_number,
  113 + 'order_type' => 7,
  114 + 'type' => 1,
  115 + 'pay_type' => 3,
  116 + 'create_time' => time()
  117 + ];
  118 + $money_detail_insert2 = $money_detail_model->insertGetId($insert);
  119 + if(!$money_detail_insert2) {
  120 + $order_model->rollback();
  121 + return false;
  122 + }
  123 + }
  124 + }
90 $order_model->commit(); 125 $order_model->commit();
91 - return $orderInfo['type']; 126 + return true;
92 } 127 }
93 } 128 }
94 129
@@ -10,6 +10,7 @@ namespace api\portal\controller; @@ -10,6 +10,7 @@ namespace api\portal\controller;
10 10
11 11
12 use api\portal\model\AgencyModel; 12 use api\portal\model\AgencyModel;
  13 +use api\portal\model\OrderModel;
13 use api\portal\model\UserNeedModel; 14 use api\portal\model\UserNeedModel;
14 use cmf\controller\HomeBaseController; 15 use cmf\controller\HomeBaseController;
15 use api\portal\model\PortalPostModel; 16 use api\portal\model\PortalPostModel;
@@ -264,6 +265,8 @@ class ThirdsendController extends HomeBaseController @@ -264,6 +265,8 @@ class ThirdsendController extends HomeBaseController
264 }else{ 265 }else{
265 $change_final['id'] = $getv; 266 $change_final['id'] = $getv;
266 $change_final['status'] = 3; 267 $change_final['status'] = 3;
  268 + // 中介报价未进入决赛,执行订单退款
  269 + $refund_result = $this->agency_order_refund($getv,'中介报价未进入决赛圈退款');
267 } 270 }
268 $agencyModel = new AgencyModel(); 271 $agencyModel = new AgencyModel();
269 $fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final); 272 $fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final);
@@ -291,18 +294,21 @@ class ThirdsendController extends HomeBaseController @@ -291,18 +294,21 @@ class ThirdsendController extends HomeBaseController
291 if(!$fianl_AgsaveNext){ 294 if(!$fianl_AgsaveNext){
292 Db::rollback(); 295 Db::rollback();
293 } 296 }
  297 + // 中介报价订单退款
  298 + $refund_result = $this->agency_order_refund($changeva,'中介报价少于3人退款');
  299 +
294 // 退回中介保证金 300 // 退回中介保证金
295 - $add_a['user_id'] = $changeva['agency_id'];  
296 - $add_a['title'] = '报价人数不足';  
297 - $add_a['type'] = 1;  
298 - $add_a['reason'] = 1;  
299 - $add_a['money'] = $changeva['deposit'];  
300 - $add_a['create_time'] = time();  
301 - $add_a['update_time'] = time();  
302 - $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);  
303 - if (!$amoney_id) {  
304 - Db::rollback();  
305 - } 301 +// $add_a['user_id'] = $changeva['agency_id'];
  302 +// $add_a['title'] = '报价人数不足';
  303 +// $add_a['type'] = 1;
  304 +// $add_a['reason'] = 1;
  305 +// $add_a['money'] = $changeva['deposit'];
  306 +// $add_a['create_time'] = time();
  307 +// $add_a['update_time'] = time();
  308 +// $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
  309 +// if (!$amoney_id) {
  310 +// Db::rollback();
  311 +// }
306 // 用户表增加金额 312 // 用户表增加金额
307 $where_member['type'] = 2; 313 $where_member['type'] = 2;
308 $where_member['id'] = $changeva['agency_id']; 314 $where_member['id'] = $changeva['agency_id'];
@@ -320,21 +326,24 @@ class ThirdsendController extends HomeBaseController @@ -320,21 +326,24 @@ class ThirdsendController extends HomeBaseController
320 Db::rollback(); 326 Db::rollback();
321 } 327 }
322 328
  329 + // 用户需求订单退款
  330 + $refund_result = $this->need_order_refund($userNeedList,'报价人数不足');
  331 +
323 // 退回保证金 332 // 退回保证金
324 // 用户 333 // 用户
325 // 加用户金额明细表 334 // 加用户金额明细表
326 - $add_del['need_id'] = $userNeedList['id'];  
327 - $add_del['user_id'] = $userNeedList['user_id'];  
328 - $add_del['title'] = '报价人数不足';  
329 - $add_del['reason'] = 1;  
330 - $add_del['type'] = 1;  
331 - $add_del['money'] = $userNeedList['pay_money'];  
332 - $add_del['create_time'] = time();  
333 - $add_del['update_time'] = time();  
334 - $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);  
335 - if (!$umoney_id) {  
336 - Db::rollback();  
337 - } 335 +// $add_del['need_id'] = $userNeedList['id'];
  336 +// $add_del['user_id'] = $userNeedList['user_id'];
  337 +// $add_del['title'] = '报价人数不足';
  338 +// $add_del['reason'] = 1;
  339 +// $add_del['type'] = 1;
  340 +// $add_del['money'] = $userNeedList['pay_money'];
  341 +// $add_del['create_time'] = time();
  342 +// $add_del['update_time'] = time();
  343 +// $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
  344 +// if (!$umoney_id) {
  345 +// Db::rollback();
  346 +// }
338 $where_memberNext['type'] = 1; 347 $where_memberNext['type'] = 1;
339 $where_memberNext['id'] = $userNeedList['user_id']; 348 $where_memberNext['id'] = $userNeedList['user_id'];
340 $add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']); 349 $add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
@@ -351,22 +360,24 @@ class ThirdsendController extends HomeBaseController @@ -351,22 +360,24 @@ class ThirdsendController extends HomeBaseController
351 if(!$fianl_Ussave){ 360 if(!$fianl_Ussave){
352 Db::rollback(); 361 Db::rollback();
353 } 362 }
  363 + // 用户需求订单退款
  364 + $refund_result = $this->need_order_refund($userNeedList,'报价人数不足');
354 365
355 // 退回保证金 366 // 退回保证金
356 // 用户 367 // 用户
357 // 加用户金额明细表 368 // 加用户金额明细表
358 - $add_del['need_id'] = $userNeedList['id'];  
359 - $add_del['user_id'] = $userNeedList['user_id'];  
360 - $add_del['title'] = '报价人数不足';  
361 - $add_del['type'] = 1;  
362 - $add_del['money'] = $userNeedList['pay_money'];  
363 - $add_del['create_time'] = time();  
364 - $add_del['update_time'] = time();  
365 - $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);  
366 - if (!$umoney_id) {  
367 - Db::rollback();  
368 - $this->apiResponse('0','金额明细添加失败');  
369 - } 369 +// $add_del['need_id'] = $userNeedList['id'];
  370 +// $add_del['user_id'] = $userNeedList['user_id'];
  371 +// $add_del['title'] = '报价人数不足';
  372 +// $add_del['type'] = 1;
  373 +// $add_del['money'] = $userNeedList['pay_money'];
  374 +// $add_del['create_time'] = time();
  375 +// $add_del['update_time'] = time();
  376 +// $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
  377 +// if (!$umoney_id) {
  378 +// Db::rollback();
  379 +// $this->apiResponse('0','金额明细添加失败');
  380 +// }
370 $where_memberNext['type'] = 1; 381 $where_memberNext['type'] = 1;
371 $where_memberNext['id'] = $userNeedList['user_id']; 382 $where_memberNext['id'] = $userNeedList['user_id'];
372 $add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']); 383 $add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
@@ -426,6 +437,10 @@ class ThirdsendController extends HomeBaseController @@ -426,6 +437,10 @@ class ThirdsendController extends HomeBaseController
426 if (!$agency_result) { 437 if (!$agency_result) {
427 Db::rollback(); 438 Db::rollback();
428 } 439 }
  440 + foreach ($agency_list as $agency_key=>$agency_val) {
  441 + // 中介报价订单退款
  442 + $refund_result = $this->agency_order_refund($agency_val,'用户未选择中标中介退款');
  443 + }
429 } 444 }
430 $where_needUpdate['id'] = $userNeedList['id']; 445 $where_needUpdate['id'] = $userNeedList['id'];
431 $needUpdate['status'] = 6; 446 $needUpdate['status'] = 6;
@@ -446,25 +461,25 @@ class ThirdsendController extends HomeBaseController @@ -446,25 +461,25 @@ class ThirdsendController extends HomeBaseController
446 Db::rollback(); 461 Db::rollback();
447 } 462 }
448 // 中介金额明细表 463 // 中介金额明细表
449 - foreach ($agency_list as $agenk=>$agenv){  
450 - $add_a['ag_id'] = $agenv['id'];  
451 - $add_a['user_id'] = $agenv['agency_id'];  
452 - $add_a['title'] = '用户未选择中介';  
453 - $add_a['type'] = 1;  
454 - $add_a['money'] = $agenv['deposit'];  
455 - $add_a['create_time'] = time();  
456 - $add_a['update_time'] = time();  
457 - $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);  
458 - if (!$amoney_id) {  
459 - Db::rollback();  
460 - }  
461 - $where_member['type'] = 2;  
462 - $where_member['id'] = $agenv['agency_id'];  
463 - $add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);  
464 - if (!$add_money) {  
465 - Db::rollback();  
466 - }  
467 - } 464 +// foreach ($agency_list as $agenk=>$agenv){
  465 +// $add_a['ag_id'] = $agenv['id'];
  466 +// $add_a['user_id'] = $agenv['agency_id'];
  467 +// $add_a['title'] = '用户未选择中介';
  468 +// $add_a['type'] = 1;
  469 +// $add_a['money'] = $agenv['deposit'];
  470 +// $add_a['create_time'] = time();
  471 +// $add_a['update_time'] = time();
  472 +// $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
  473 +// if (!$amoney_id) {
  474 +// Db::rollback();
  475 +// }
  476 +// $where_member['type'] = 2;
  477 +// $where_member['id'] = $agenv['agency_id'];
  478 +// $add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
  479 +// if (!$add_money) {
  480 +// Db::rollback();
  481 +// }
  482 +// }
468 483
469 } 484 }
470 } 485 }
@@ -949,6 +964,105 @@ class ThirdsendController extends HomeBaseController @@ -949,6 +964,105 @@ class ThirdsendController extends HomeBaseController
949 } 964 }
950 965
951 966
  967 + /**
  968 + * 需求订单退款
  969 + * @param needInfo 用户需求信息
  970 + * @param reason 退款原因
  971 + */
  972 + private function need_order_refund($needInfo,$reason) {
  973 + $order_model = new OrderModel();
  974 + $where = [
  975 + 'user_id' => $needInfo['user_id'],
  976 + 'type' => 1,
  977 + 'need_id' => $needInfo['id'],
  978 + 'is_get' => 2,
  979 + 'status' => 2
  980 + ];
  981 + // 根据不同订单类型执行退款操作
  982 + $orderInfo = $order_model->where($where)->find();
  983 + $transaction_id = $orderInfo['transaction_id'];
  984 + $order_sn = $orderInfo['order_sn'];
  985 + $money = $orderInfo['money'];
  986 + $out_refund_no = cmf_get_order_sn();
  987 + // 微信
  988 + $refund_result = false;
  989 + if($orderInfo['pay_type'] == 1 || $orderInfo['pay_type'] == 2) {
  990 + $refund_result = $this->wxpay_refund($transaction_id,$out_refund_no,$money,$money,$reason);
  991 + }
  992 + // 支付宝
  993 + if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
  994 + $refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
  995 + }
  996 + return $refund_result;
  997 + }
  998 +
  999 + /**
  1000 + * 中介报价退款
  1001 + * @param agencyInfo 中介报价信息
  1002 + * @param reason 退款原因
  1003 + */
  1004 + private function agency_order_refund($agencyInfo,$reason) {
  1005 + $order_model = new OrderModel();
  1006 + $where = [
  1007 + 'user_id' => $agencyInfo['agency_id'],
  1008 + 'type' => 2,
  1009 + 'need_id' => $agencyInfo['id'],
  1010 + 'is_get' => 2,
  1011 + 'status' => 2
  1012 + ];
  1013 + // 根据不同订单类型执行退款操作
  1014 + $orderInfo = $order_model->where($where)->find();
  1015 + $transaction_id = $orderInfo['transaction_id'];
  1016 + $order_sn = $orderInfo['order_sn'];
  1017 + $money = $orderInfo['money'];
  1018 + $out_refund_no = cmf_get_order_sn();
  1019 + $refund_result = false;
  1020 + // 微信
  1021 + if($orderInfo['pay_type'] == 1 || $orderInfo['pay_type'] == 2) {
  1022 + $refund_result = $this->wxpay_refund($transaction_id,$out_refund_no,$money,$money,$reason);
  1023 + }
  1024 + // 支付宝
  1025 + if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
  1026 + $refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
  1027 + }
  1028 + return $refund_result;
  1029 + }
  1030 +
  1031 + /**
  1032 + * 支付宝退款接口(两个订单号不能同时为空)
  1033 + * @param trade_no 支付宝交易号
  1034 + * @param out_trade_no 商户支付订单号
  1035 + * @param refund_amount 退款金额
  1036 + * @param refund_reason 退款原因
  1037 + * @param out_request_no 如需部分退款,传此参数
  1038 + */
  1039 + private function alipay_refund($trade_no = null, $out_trade_no = null, $refund_amount, $refund_reason, $out_request_no = null) {
  1040 + $refund = controller('Alipay','controller');
  1041 + $data = [
  1042 + 'trade_no' => $trade_no,
  1043 + 'out_trade_no' => $out_trade_no,
  1044 + 'refund_amount' => $refund_amount,
  1045 + 'refund_reason' => $refund_reason,
  1046 + 'out_request_no' => $out_request_no
  1047 + ];
  1048 + return $refund->refund($data);
  1049 + }
  1050 +
  1051 + /**
  1052 + * 微信退款接口(两个订单号不能同时为空)
  1053 + * @param transaction_id 微信业务订单号
  1054 + * @param out_refund_no 商户退款订单号
  1055 + * @param total_fee 订单金额
  1056 + * @param refund_fee 退款金额
  1057 + * @param refund_desc 退款原因
  1058 + */
  1059 + private function wxpay_refund($transaction_id = null, $out_refund_no = null, $total_fee, $refund_fee, $refund_desc) {
  1060 + require_once VENDOR_PATH.'WxpayAPI/WxRefund.php';
  1061 + $refund = new \WxRefund(Config::get('wx_appid'),Config::get('wx_mch_id'),Config::get('wx_key'),$transaction_id,
  1062 + $out_refund_no,$total_fee,$refund_fee,$refund_desc);
  1063 + return $refund->pay();
  1064 + }
  1065 +
952 1066
953 1067
954 } 1068 }
@@ -79,6 +79,7 @@ class UserController extends CommonController @@ -79,6 +79,7 @@ class UserController extends CommonController
79 * @method POST 79 * @method POST
80 * @param name:tel type:int require:1 default: other: desc:手机号 80 * @param name:tel type:int require:1 default: other: desc:手机号
81 * @param name:imgCode type:int require:1 default: other:genre=2时传 desc:图片验证码 81 * @param name:imgCode type:int require:1 default: other:genre=2时传 desc:图片验证码
  82 + * @param name:rand type:int require:1 default: other: desc:随机数
82 * @param name:genre type:int require:1 default: other: desc:类型(1->用户注册/中介注册,2->密码找回,3->发布需求,4->修改手机号,5->绑定银行卡) 83 * @param name:genre type:int require:1 default: other: desc:类型(1->用户注册/中介注册,2->密码找回,3->发布需求,4->修改手机号,5->绑定银行卡)
83 * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1 84 * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1
84 */ 85 */
@@ -108,7 +109,7 @@ class UserController extends CommonController @@ -108,7 +109,7 @@ class UserController extends CommonController
108 }else if($genre == 2 ){ 109 }else if($genre == 2 ){
109 // 验证图形验证码 110 // 验证图形验证码
110 // 验证码 111 // 验证码
111 - session_start(); 112 +// session_start();
112 if(empty($data['imgCode'])){ 113 if(empty($data['imgCode'])){
113 $this->apiResponse('0','请先输入图形验证码'); 114 $this->apiResponse('0','请先输入图形验证码');
114 } 115 }
@@ -588,7 +589,7 @@ class UserController extends CommonController @@ -588,7 +589,7 @@ class UserController extends CommonController
588 * @param name:code type:int require:1 default: other: desc:短信验证码 589 * @param name:code type:int require:1 default: other: desc:短信验证码
589 * @param name:newPassword type:int require:1 default: other: desc:新密码 590 * @param name:newPassword type:int require:1 default: other: desc:新密码
590 * @param name:sureNewPassword type:int require:1 default: other: desc:确认新密码 591 * @param name:sureNewPassword type:int require:1 default: other: desc:确认新密码
591 - * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:2 592 + * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1
592 */ 593 */
593 public function findPassword(Request $request){ 594 public function findPassword(Request $request){
594 $data = $request->param(); 595 $data = $request->param();
@@ -229,5 +229,9 @@ $configs = [ @@ -229,5 +229,9 @@ $configs = [
229 'cmf_default_theme' => 'simpleboot3', 229 'cmf_default_theme' => 'simpleboot3',
230 'cmf_admin_theme_path' => 'themes/', 230 'cmf_admin_theme_path' => 'themes/',
231 'cmf_admin_default_theme' => 'admin_simpleboot3', 231 'cmf_admin_default_theme' => 'admin_simpleboot3',
  232 + 'wx_appid' => 'wxf69d1d87d173c899',
  233 + 'wx_appsecret' => '93c020c51020d87bda1c0bd98b527ff5',
  234 + 'wx_mch_id' => '1507884301',
  235 + 'wx_key' => 'VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI',
232 ]; 236 ];
233 return array_merge($configs, $runtimeConfig); 237 return array_merge($configs, $runtimeConfig);
@@ -28,16 +28,19 @@ class IndexController extends CommonController @@ -28,16 +28,19 @@ class IndexController extends CommonController
28 { 28 {
29 public function index() 29 public function index()
30 { 30 {
31 - $return = $this->wxpay(['order_sn'=>201807211032],'保证金支付'); 31 +// $return = $this->wxpay(['order_sn'=>201807211101],'保证金支付');
32 // $qrcode_url = url('portal/Index/qrcode',['data'=>urlencode($return['code_url'])],true,true); 32 // $qrcode_url = url('portal/Index/qrcode',['data'=>urlencode($return['code_url'])],true,true);
33 // echo '<img src="'.$qrcode_url.'" alt=""/>'; 33 // echo '<img src="'.$qrcode_url.'" alt=""/>';
34 - $back = [  
35 - 'return'=>$return, 34 +// $back = [
  35 +// 'return'=>$return,
36 // 'code_url'=>base64_encode($return['code_url']), 36 // 'code_url'=>base64_encode($return['code_url']),
37 // 'qrcode'=> '<img src="'.$qrcode_url.'" alt=""/>', 37 // 'qrcode'=> '<img src="'.$qrcode_url.'" alt=""/>',
38 - 'alipay_url'=>url('portal/Alipay/alipay',array('order_sn'=>201807211032,'name'=>'保证金支付','price'=>0.01))  
39 - ];  
40 - $this->redirect($back['alipay_url']); 38 +// 'alipay_url'=>url('portal/Alipay/alipay',array('order_sn'=>201807211101,'name'=>'保证金支付','price'=>0.01))
  39 +// ];
  40 +// $this->redirect($back['alipay_url']);
  41 +
  42 + $alipay_url = url('portal/Alipay/refund',array('trade_no'=>'2018072421001004410576233593','refund_amount'=>0.01,'refund_reason'=>'中介报价少于3人退款'));
  43 + $this->redirect($alipay_url);
41 44
42 // echo "<pre/>"; 45 // echo "<pre/>";
43 // print_r('7777'); 46 // print_r('7777');
@@ -81,13 +84,15 @@ class IndexController extends CommonController @@ -81,13 +84,15 @@ class IndexController extends CommonController
81 // 微信h5支付(测试) 84 // 微信h5支付(测试)
82 public function wxpayh5() { 85 public function wxpayh5() {
83 require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php'; 86 require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
84 - $h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','YkeE7j21vdwqnBYW8FM2Z11O9T4v1kH0','201807211100',  
85 - '保证金支付','1','','保证金支付'); 87 + $h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI','201807211465',
  88 + '保证金支付','1','{"h5_info": {"type":"Wap","wap_url": "http://houseprice.w.bronet.cn","wap_name": "保证金支付"}}' );
86 $result = $h5->pay(); 89 $result = $h5->pay();
87 var_dump($result); 90 var_dump($result);
  91 + $mweb_url = '';
88 if(!empty($result['mweb_url'])) { 92 if(!empty($result['mweb_url'])) {
89 - $this->assign('mwen_url',$result['mweb_url']); 93 + $mweb_url = $result['mweb_url'];
90 } 94 }
  95 + $this->assign('mwen_url',$mweb_url);
91 return $this->fetch(':h5'); 96 return $this->fetch(':h5');
92 } 97 }
93 98
@@ -114,7 +119,7 @@ class IndexController extends CommonController @@ -114,7 +119,7 @@ class IndexController extends CommonController
114 require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php'; 119 require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
115 // $h5 = new \WxpayH5(config('APP_ID'),config('MCH_ID'),config('WXPAY_KEY'),$data['order_sn'], 120 // $h5 = new \WxpayH5(config('APP_ID'),config('MCH_ID'),config('WXPAY_KEY'),$data['order_sn'],
116 // $type[$data['_type']],'1',$scene_info); 121 // $type[$data['_type']],'1',$scene_info);
117 - $h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','YkeE7j21vdwqnBYW8FM2Z11O9T4v1kH0',$data['order_sn'], 122 + $h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI',$data['order_sn'],
118 $type[$data['_type']],'1',$scene_info); 123 $type[$data['_type']],'1',$scene_info);
119 $result = $h5->pay(); 124 $result = $h5->pay();
120 if(empty($result['mweb_url'])) { 125 if(empty($result['mweb_url'])) {
@@ -129,6 +134,15 @@ class IndexController extends CommonController @@ -129,6 +134,15 @@ class IndexController extends CommonController
129 } 134 }
130 } 135 }
131 136
  137 + // 微信退款(测试)
  138 + public function wxrefund() {
  139 + require_once VENDOR_PATH.'WxpayAPI/WxRefund.php';
  140 + $refund = new \WxRefund('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI','4200000146201807232084354569',
  141 + '201807250936','1','1','中介报价少于3人退款');
  142 + $result = $refund->pay();
  143 + var_dump($result);
  144 + }
  145 +
132 public function callback() { 146 public function callback() {
133 echo 111; 147 echo 111;
134 } 148 }
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 // | Author: 老猫 <thinkcmf@126.com> 9 // | Author: 老猫 <thinkcmf@126.com>
10 // +---------------------------------------------------------------------- 10 // +----------------------------------------------------------------------
11 namespace app\portal\controller; 11 namespace app\portal\controller;
  12 +use app\portal\model\UserNeedModel;
12 use cmf\controller\AdminBaseController; 13 use cmf\controller\AdminBaseController;
13 use app\portal\model\NeedAnswerModel; 14 use app\portal\model\NeedAnswerModel;
14 use app\portal\model\MemberModel; 15 use app\portal\model\MemberModel;
@@ -28,9 +29,9 @@ class NeedController extends AdminBaseController @@ -28,9 +29,9 @@ class NeedController extends AdminBaseController
28 // 列表 29 // 列表
29 public function index(Request $request) 30 public function index(Request $request)
30 { 31 {
31 -// $where_coo['status'] = 1; 32 + $where_coo['n.status'] = array('neq',9);
32 // $where_coo['type'] = 2; 33 // $where_coo['type'] = 2;
33 - $where_coo = array(); 34 +// $where_coo = array();
34 if($request->post()){ 35 if($request->post()){
35 $search = $request->post(); 36 $search = $request->post();
36 if($search['start_time']){ 37 if($search['start_time']){
@@ -82,52 +83,64 @@ class NeedController extends AdminBaseController @@ -82,52 +83,64 @@ class NeedController extends AdminBaseController
82 // 修改信息 83 // 修改信息
83 public function change(Request $request) 84 public function change(Request $request)
84 { 85 {
85 - if($request->post()){  
86 -// 添加数据  
87 - $data = $request->post();  
88 - if($request->Post('id')){  
89 -// 修改  
90 - $add['content'] = $data['content'];  
91 - $add['title'] = $data['title'];  
92 - $add['score'] = $data['score'];  
93 - $add['type'] = 2;  
94 - $validate = Loader::validate('NeedAnswer');  
95 - if(!$validate->scene('edit')->check($add)){  
96 - $mes = $validate->getError();  
97 - $this->error("$mes");  
98 - }  
99 - $add['id'] = $request->param('id');  
100 - $model = new NeedAnswerModel();  
101 - $final = $model->isUpdate(true)->allowField(true)->save($add); 86 + $data = $request->Post();
  87 + $validate = Loader::validate('UserNeed');
  88 + if(!$validate->check($_POST)){
  89 + return json(array('code'=>0,'msg'=>$validate->getError()));
  90 + }
  91 +// 加数据库
  92 +// 保证金
  93 + $city = $data['city'];
  94 + $area = $data['area'];
  95 +// 查询地区
  96 + $where_area['area_name'] = array('like',"%$city%");
  97 + $city_id = Db::name('Areas')->where($where_area)->field('area_id')->find();
  98 + $where_money['city'] = array('like',"%".$city_id['area_id'].'%');
  99 + $where_money['status'] = 1;
  100 + $where_money['low_area'] = array('lt',$area);
  101 + $where_money['height_area'] = array('egt',$area);
  102 + $money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
  103 + if(!$money){
  104 + $where_elsemoney['city'] = 0;
  105 + $where_elsemoney['status'] = 1;
  106 + $where_elsemoney['low_area'] = array('lt',$area);
  107 + $where_elsemoney['height_area'] = array('egt',$area);
  108 + $elsemoney = Db::name('MoneyRule')->where($where_elsemoney)->field('money')->find();
  109 + if($elsemoney){
  110 + $data['pay_money'] = $elsemoney['money'];
102 }else{ 111 }else{
103 -// 添加  
104 - $add['content'] = $data['content'];  
105 - $add['title'] = $data['title'];  
106 - $add['score'] = $data['score'];  
107 - $add['type'] = 2;  
108 - $validate = Loader::validate('NeedAnswer');  
109 - if(!$validate->scene('add')->check($add)){  
110 - $mes = $validate->getError();  
111 - $this->error("$mes"); 112 + $this->error('保证金获取失败');
112 } 113 }
113 -  
114 - $model = new NeedAnswerModel();  
115 - $final = $model->save($add);  
116 - }  
117 - if($final){  
118 - $this->success('成功',url('index'));  
119 }else{ 114 }else{
120 - $this->error('失败'); 115 + $data['pay_money'] = $money['money'];
121 } 116 }
  117 +
  118 + $model = new UserNeedModel();
  119 +// 修改
  120 + $where_need['id'] = $request->param('id');
  121 + $where_need['status'] = array('neq',9);
  122 + $need = Db::name('UserNeed')->where($where_need)->find();
  123 + $data['user_id'] = $need['user_id'];
  124 + if(!$need){
  125 + $this->error('该需求不可修改');
122 }else{ 126 }else{
123 - $where_find['type'] = $request->param('id');  
124 - $list = Db::name('NeedAnswer')->where($where_find)->find();  
125 - if($list){  
126 - $list['content'] = htmlspecialchars_decode($list['content']);  
127 - }  
128 - $this->assign('list',$list);  
129 - return $this->fetch('add'); 127 +// $data['id'] = $data['need_id'];
  128 + if($need['status'] == 2){
  129 + unset($data['pay_money']);
  130 + }
  131 + $data['create_time'] = strtotime($data['create_time']);
  132 + $data['update_time'] = strtotime($data['update_time']);
  133 + $data['pay_time'] = strtotime($data['pay_time']);
  134 + $data['choose_time'] = strtotime($data['choose_time']);
  135 + $save = $model->isUpdate(true)->allowField(true)->save($data);
  136 + }
  137 + if($save){
  138 + $final['need_id'] = $model->id;
  139 + $this->success('修改成功',url('Need/index'));
  140 + }else{
  141 + $this->error('修改失败');
130 } 142 }
  143 +
131 } 144 }
132 145
133 146
@@ -143,7 +156,7 @@ class NeedController extends AdminBaseController @@ -143,7 +156,7 @@ class NeedController extends AdminBaseController
143 $this->error('删除失败'); 156 $this->error('删除失败');
144 } 157 }
145 $add_del['status'] = 9; 158 $add_del['status'] = 9;
146 - $model = new NeedAnswerModel(); 159 + $model = new UserNeedModel();
147 $del = $model->isUpdate(true)->allowField(true)->save($add_del); 160 $del = $model->isUpdate(true)->allowField(true)->save($add_del);
148 if($del){ 161 if($del){
149 $this->success('删除成功',url('index')); 162 $this->success('删除成功',url('index'));
@@ -3,8 +3,7 @@ @@ -3,8 +3,7 @@
3 <body> 3 <body>
4 <div class="wrap js-check-wrap"> 4 <div class="wrap js-check-wrap">
5 <ul class="nav nav-tabs"> 5 <ul class="nav nav-tabs">
6 - <li class="active"><a href=" ">保证金说明列表</a></li>  
7 - <li><a href="{:url('Need/add')}">添加保证金说明</a></li> 6 + <li class="active"><a href=" ">需求列表</a></li>
8 </ul> 7 </ul>
9 <form class="well form-inline margin-top-20" method="post" action="{:url('Need/index')}"> 8 <form class="well form-inline margin-top-20" method="post" action="{:url('Need/index')}">
10 <!--分类:--> 9 <!--分类:-->
@@ -27,35 +26,6 @@ @@ -27,35 +26,6 @@
27 </form> 26 </form>
28 <form class="js-ajax-form" action="" method="post"> 27 <form class="js-ajax-form" action="" method="post">
29 <div class="table-actions"> 28 <div class="table-actions">
30 - <!--<notempty name="category">-->  
31 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
32 - <!--data-action="{:url('AdminArticle/listOrder')}">{:lang('SORT')}-->  
33 - <!--</button>-->  
34 - <!--</notempty>-->  
35 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
36 - <!--data-action="{:url('AdminArticle/publish',array('yes'=>1))}" data-subcheck="true">发布-->  
37 - <!--</button>-->  
38 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
39 - <!--data-action="{:url('AdminArticle/publish',array('no'=>1))}" data-subcheck="true">取消发布-->  
40 - <!--</button>-->  
41 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
42 - <!--data-action="{:url('AdminArticle/top',array('yes'=>1))}" data-subcheck="true">置顶-->  
43 - <!--</button>-->  
44 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
45 - <!--data-action="{:url('AdminArticle/top',array('no'=>1))}" data-subcheck="true">取消置顶-->  
46 - <!--</button>-->  
47 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
48 - <!--data-action="{:url('AdminArticle/recommend',array('yes'=>1))}" data-subcheck="true">推荐-->  
49 - <!--</button>-->  
50 - <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->  
51 - <!--data-action="{:url('AdminArticle/recommend',array('no'=>1))}" data-subcheck="true">取消推荐-->  
52 - <!--</button>-->  
53 - <!--  
54 - <notempty name="category">  
55 - <button class="btn btn-primary btn-sm js-articles-move" type="button">批量移动</button>  
56 - </notempty>  
57 - <button class="btn btn-primary btn-sm js-articles-copy" type="button">批量复制</button>  
58 - -->  
59 <button class="btn btn-danger btn-sm js-ajax-submit" type="submit" 29 <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
60 data-action="{:url('Need/del')}" data-subcheck="true" data-msg="您确定删除吗?"> 30 data-action="{:url('Need/del')}" data-subcheck="true" data-msg="您确定删除吗?">
61 {:lang('DELETE')} 31 {:lang('DELETE')}
@@ -84,6 +54,7 @@ @@ -84,6 +54,7 @@
84 <th>状态</th> 54 <th>状态</th>
85 <th>提交时间</th> 55 <th>提交时间</th>
86 <th>操作</th> 56 <th>操作</th>
  57 + <th>操作</th>
87 </tr> 58 </tr>
88 </thead> 59 </thead>
89 <foreach name="list" item="list"> 60 <foreach name="list" item="list">
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: 29925
  5 + * Date: 2018/7/21
  6 + * Time: 11:39
  7 + */
  8 +
  9 +/*
  10 + * 微信退款
  11 + */
  12 +class WxRefund {
  13 +
  14 +
  15 + protected $appid;
  16 + protected $mch_id;
  17 + protected $key;
  18 + protected $transaction_id;
  19 + protected $out_refund_no;
  20 + protected $total_fee;
  21 + protected $refund_fee;
  22 + protected $refund_desc;
  23 + function __construct($appid, $mch_id, $key, $transaction_id, $out_refund_no, $total_fee, $refund_fee, $refund_desc) {
  24 + $this->appid = $appid;
  25 + $this->mch_id = $mch_id;
  26 + $this->key = $key;
  27 + $this->transaction_id = $transaction_id;
  28 + $this->out_refund_no = $out_refund_no;
  29 + $this->total_fee = $total_fee;
  30 + $this->refund_fee = $refund_fee;
  31 + $this->refund_desc = $refund_desc;
  32 + }
  33 +
  34 +
  35 + public function pay() {
  36 + //微信退款
  37 + $return = $this->weixinrefund();
  38 + return $return;
  39 + }
  40 +
  41 +
  42 + //退款接口
  43 + private function refund() {
  44 + $url = 'https://api.mch.weixin.qq.com/secapi/pay/refund';
  45 + $parameters = array(
  46 + 'appid' => $this->appid, //appID
  47 + 'mch_id' => $this->mch_id, //商户号
  48 + 'nonce_str' => $this->createNoncestr(), //随机字符串
  49 + 'transaction_id' => $this->transaction_id,
  50 +// 'out_trade_no' => '2015450806125348', //商户订单号
  51 + 'out_refund_no'=> $this->out_refund_no,
  52 +// 'total_fee' => floatval(0.01 * 100), //总金额 单位 分
  53 + 'total_fee' => $this->total_fee,
  54 + 'refund_fee' => $this->refund_fee,
  55 + 'notify_url' => url('portal/Notify/notify', '', '', true), //通知地址 确保外网能正常访问
  56 + 'refund_desc' => $this->refund_desc
  57 + );
  58 + //统一下单签名
  59 + $parameters['sign'] = $this->getSign($parameters);
  60 + $xmlData = $this->arrayToXmlT($parameters);
  61 + $return = $this->xmlToArray($this->postXmlCurl($xmlData, $url, 60,1));
  62 + return $return;
  63 + }
  64 +
  65 + private static function postXmlCurl($xml, $url, $second = 30,$pem = null)
  66 + {
  67 + $ch = curl_init();
  68 + //设置超时
  69 + curl_setopt($ch, CURLOPT_TIMEOUT, $second);
  70 + curl_setopt($ch, CURLOPT_URL, $url);
  71 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  72 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //严格校验
  73 + //设置header
  74 + curl_setopt($ch, CURLOPT_HEADER, FALSE);
  75 + //要求结果为字符串且输出到屏幕上
  76 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  77 + //post提交方式
  78 + curl_setopt($ch, CURLOPT_POST, TRUE);
  79 + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  80 + if($pem) {
  81 + //以下是证书相关代码
  82 + curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
  83 + curl_setopt($ch,CURLOPT_SSLCERT,VENDOR_PATH.'WxpayAPI/cert/apiclient_cert.pem');//绝对路径
  84 + curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
  85 + curl_setopt($ch,CURLOPT_SSLKEY,VENDOR_PATH.'WxpayAPI/cert/apiclient_key.pem');//绝对路径
  86 + }
  87 +
  88 + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
  89 + curl_setopt($ch, CURLOPT_TIMEOUT, 40);
  90 + set_time_limit(0);
  91 +
  92 +
  93 + //运行curl
  94 + $data = curl_exec($ch);
  95 + //返回结果
  96 + if ($data) {
  97 + curl_close($ch);
  98 + return $data;
  99 + } else {
  100 + $error = curl_errno($ch);
  101 + curl_close($ch);
  102 + return $error;
  103 +// throw new WxPayException("curl出错,错误码:$error");
  104 + }
  105 + }
  106 +
  107 + //数组转换成xml
  108 + private function arrayToXml($arr) {
  109 + $xml = "<root>";
  110 + foreach ($arr as $key => $val) {
  111 + if (is_array($val)) {
  112 + $xml .= "<" . $key . ">" . arrayToXml($val) . "</" . $key . ">";
  113 + } else {
  114 + $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
  115 + }
  116 + }
  117 + $xml .= "</root>";
  118 + return $xml;
  119 + }
  120 +
  121 + //数组转换成xml
  122 + private function arrayToXmlT($arr) {
  123 + $xml = "<xml>";
  124 + foreach ($arr as $key => $val) {
  125 + if (is_array($val)) {
  126 + $xml .= "<" . $key . ">" . arrayToXmlT($val) . "</" . $key . ">";
  127 + } else {
  128 + $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
  129 + }
  130 + }
  131 + $xml .= "</xml>";
  132 + return $xml;
  133 + }
  134 +
  135 +
  136 + //xml转换成数组
  137 + private function xmlToArray($xml) {
  138 +
  139 +
  140 + //禁止引用外部xml实体
  141 +
  142 +
  143 + libxml_disable_entity_loader(true);
  144 +
  145 +
  146 + $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  147 +
  148 +
  149 + $val = json_decode(json_encode($xmlstring), true);
  150 +
  151 +
  152 + return $val;
  153 + }
  154 +
  155 +
  156 + //微信接口
  157 + private function weixinrefund() {
  158 + //退款接口
  159 + $refund = $this->refund();
  160 + return $refund;
  161 +// print_r($unifiedorder);
  162 + $parameters = array(
  163 + 'appId' => $this->appid, //小程序ID
  164 + 'timeStamp' => '' . time() . '', //时间戳
  165 + 'nonceStr' => $this->createNoncestr(), //随机串
  166 + 'package' => 'prepay_id=' . $refund['prepay_id'], //数据包
  167 + 'signType' => 'MD5'//签名方式
  168 + );
  169 + //签名
  170 + $parameters['paySign'] = $this->getSign($parameters);
  171 + return $parameters;
  172 + }
  173 +
  174 +
  175 + //作用:产生随机字符串,不长于32位
  176 + private function createNoncestr($length = 32) {
  177 + $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  178 + $str = "";
  179 + for ($i = 0; $i < $length; $i++) {
  180 + $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  181 + }
  182 + return $str;
  183 + }
  184 +
  185 +
  186 + //作用:生成签名
  187 + private function getSign($Obj) {
  188 + foreach ($Obj as $k => $v) {
  189 + $Parameters[$k] = $v;
  190 + }
  191 + //签名步骤一:按字典序排序参数
  192 + ksort($Parameters);
  193 + $String = $this->formatBizQueryParaMap($Parameters, false);
  194 + //签名步骤二:在string后加入KEY
  195 + $String = $String . "&key=" . $this->key;
  196 + //签名步骤三:MD5加密
  197 + $String = md5($String);
  198 + //签名步骤四:所有字符转为大写
  199 + $result_ = strtoupper($String);
  200 + return $result_;
  201 + }
  202 +
  203 +
  204 + ///作用:格式化参数,签名过程需要使用
  205 + private function formatBizQueryParaMap($paraMap, $urlencode) {
  206 + $buff = "";
  207 + ksort($paraMap);
  208 + foreach ($paraMap as $k => $v) {
  209 + if ($urlencode) {
  210 + $v = urlencode($v);
  211 + }
  212 + $buff .= $k . "=" . $v . "&";
  213 + }
  214 + $reqPar = "";
  215 + if (strlen($buff) > 0) {
  216 + $reqPar = substr($buff, 0, strlen($buff) - 1);
  217 + }
  218 + return $reqPar;
  219 + }
  220 +
  221 +
  222 +}
@@ -19,7 +19,6 @@ class WxpayH5 { @@ -19,7 +19,6 @@ class WxpayH5 {
19 protected $body; 19 protected $body;
20 protected $total_fee; 20 protected $total_fee;
21 protected $scene_info; 21 protected $scene_info;
22 - protected $type;  
23 function __construct($appid, $mch_id, $key,$out_trade_no,$body,$total_fee,$scene_info) { 22 function __construct($appid, $mch_id, $key,$out_trade_no,$body,$total_fee,$scene_info) {
24 $this->appid = $appid; 23 $this->appid = $appid;
25 $this->mch_id = $mch_id; 24 $this->mch_id = $mch_id;
@@ -32,17 +31,17 @@ class WxpayH5 { @@ -32,17 +31,17 @@ class WxpayH5 {
32 31
33 32
34 public function pay() { 33 public function pay() {
35 - //统一下单接口 34 + //H5支付接口
36 $return = $this->weixinapp(); 35 $return = $this->weixinapp();
37 return $return; 36 return $return;
38 } 37 }
39 38
40 39
41 - //统一下单接口 40 + //H5支付接口
42 private function unifiedorder() { 41 private function unifiedorder() {
43 $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; 42 $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
44 $parameters = array( 43 $parameters = array(
45 - 'appid' => $this->appid, //小程序ID 44 + 'appid' => $this->appid, //appID
46 'mch_id' => $this->mch_id, //商户号 45 'mch_id' => $this->mch_id, //商户号
47 'nonce_str' => $this->createNoncestr(), //随机字符串 46 'nonce_str' => $this->createNoncestr(), //随机字符串
48 // 'body' => 'test', //商品描述 47 // 'body' => 'test', //商品描述
@@ -154,14 +153,14 @@ class WxpayH5 { @@ -154,14 +153,14 @@ class WxpayH5 {
154 } 153 }
155 154
156 155
157 - //微信小程序接口 156 + //H5支付接口
158 private function weixinapp() { 157 private function weixinapp() {
159 - //统一下单接口 158 + //H5支付接口
160 $unifiedorder = $this->unifiedorder(); 159 $unifiedorder = $this->unifiedorder();
161 return $unifiedorder; 160 return $unifiedorder;
162 // print_r($unifiedorder); 161 // print_r($unifiedorder);
163 $parameters = array( 162 $parameters = array(
164 - 'appId' => $this->appid, //小程序ID 163 + 'appId' => $this->appid, //appID
165 'timeStamp' => '' . time() . '', //时间戳 164 'timeStamp' => '' . time() . '', //时间戳
166 'nonceStr' => $this->createNoncestr(), //随机串 165 'nonceStr' => $this->createNoncestr(), //随机串
167 'package' => 'prepay_id=' . $unifiedorder['prepay_id'], //数据包 166 'package' => 'prepay_id=' . $unifiedorder['prepay_id'], //数据包