From ac1e5066703c98b26b887f1412db9f8d87dfcb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Wed, 8 Nov 2017 01:05:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/UserRechargeController.php | 26 +++- .../Controllers/Api/WechatAuthController.php | 117 ------------------ .../Controllers/Weixin/UserController.php | 14 +++ app/Http/Model/UserRecharge.php | 1 + .../views/weixin/user/userRecharge.blade.php | 9 +- .../weixin/user/userRechargeTwo.blade.php | 91 ++++++++++++++ routes/web.php | 8 +- 7 files changed, 140 insertions(+), 126 deletions(-) delete mode 100644 app/Http/Controllers/Api/WechatAuthController.php create mode 100644 resources/views/weixin/user/userRechargeTwo.blade.php diff --git a/app/Http/Controllers/Api/UserRechargeController.php b/app/Http/Controllers/Api/UserRechargeController.php index da2f9b3..6c3e71e 100644 --- a/app/Http/Controllers/Api/UserRechargeController.php +++ b/app/Http/Controllers/Api/UserRechargeController.php @@ -33,16 +33,36 @@ class UserRechargeController extends CommonController return ReturnData::create(ReturnData::SUCCESS,$res); } + //获取一条用户充值 + public function userRechargeDetail(Request $request) + { + //参数 + $data['id'] = $request->input('id', ''); + if($data['id']=='') + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + $data['user_id'] = Token::$uid; + + $res = UserRecharge::getOne($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + //添加充值记录 public function userRechargeAdd(Request $request) { //参数 $data['money'] = $request->input('money',''); - if($request->input('status', '') != ''){$data['status'] = $request->input('status');} - if($request->input('pay_type', '') != ''){$data['pay_type'] = $request->input('pay_type');} + $data['status'] = UserRecharge::UN_PAY; //0未处理,1已完成 + $data['pay_type'] = $request->input('pay_type',''); //充值类型:1微信,2支付宝 $data['user_id'] = Token::$uid; - if($data['money']=='') + if($data['money']=='' || $data['pay_type']=='') { return ReturnData::create(ReturnData::PARAMS_ERROR); } diff --git a/app/Http/Controllers/Api/WechatAuthController.php b/app/Http/Controllers/Api/WechatAuthController.php deleted file mode 100644 index 4aec40a..0000000 --- a/app/Http/Controllers/Api/WechatAuthController.php +++ /dev/null @@ -1,117 +0,0 @@ -code = $this->getCode(); - $this->access_token = $this->getOpenId(); - $userInfo = $this->getUserInfo(); - - //把用户的微信信息存到数据库中 - /* if ($userInfo) - { - $ins = M('Wechat_user_info'); - $map['openid'] = $userInfo['openid']; - $result = $ins->where($map)->find(); //根据OPENID查找数据库中是否有这个用户,如果没有就写数据库。继承该类的其他类,用户都写入了数据库中。 - - if (!$result) - { - $ins->add($userInfo); - } - - $_SESSION['openid'] = $userInfo['openid']; //写到$_SESSION中。微信缓存很坑爹,调试时请及时清除缓存再试。 - } */ - } - } - - /** - * @explain - * 获取code,用于获取openid和access_token - * @remark - * code只能使用一次,当获取到之后code失效,再次获取需要重新进入 - * 不会弹出授权页面,适用于关注公众号后自定义菜单跳转等,如果不关注,那么只能获取openid - **/ - public function getCode() - { - if (isset($_REQUEST["code"])) - { - return $_REQUEST["code"]; - } - else - { - $str = "location: https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $this->appid . "&redirect_uri=" . $this->redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=". $this->state ."#wechat_redirect"; - header($str); - exit; - } - } - - /** - * @explain - * 用于获取用户openid - **/ - public function getOpenId() - { - $access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $this->appid . "&secret=" . $this->appsecret . "&code=" . $this->code . "&grant_type=authorization_code"; - $access_token_json = $this->https_request($access_token_url); - $access_token_array = json_decode($access_token_json, TRUE); - - return $access_token_array; - } - - /** - * @explain - * 通过code获取用户openid以及用户的微信号信息 - * @return - * @remark - * 获取到用户的openid之后可以判断用户是否有数据,可以直接跳过获取access_token,也可以继续获取access_token - * access_token每日获取次数是有限制的,access_token有时间限制,可以存储到数据库7200s. 7200s后access_token失效 - **/ - public function getUserInfo() - { - $userinfo_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$this->access_token['access_token'] ."&openid=" . $this->access_token['openid']."&lang=zh_CN"; - $userinfo_json = $this->https_request($userinfo_url); - $userinfo_array = json_decode($userinfo_json, TRUE); - - return $userinfo_array; - } - - - /** - * @explain - * 发送http请求,并返回数据 - **/ - public function https_request($url, $data = null) - { - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); - - if (!empty($data)) - { - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - } - - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - $output = curl_exec($curl); - curl_close($curl); - - return $output; - } -} \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index 2024182..a11876f 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -62,6 +62,20 @@ class UserController extends CommonController return view('weixin.user.userRecharge'); } + //用户充值第二步,支付 + public function userRechargeTwo($id) + { + $postdata = array( + 'id' => $id, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_recharge_detail"; + $res = curl_request($url,$postdata,'GET'); + $data['post'] = $res['data']; + + return view('weixin.user.userRechargeTwo', $data); + } + //余额明细 public function userMoneyList(Request $request) { diff --git a/app/Http/Model/UserRecharge.php b/app/Http/Model/UserRecharge.php index 514cf91..3337033 100644 --- a/app/Http/Model/UserRecharge.php +++ b/app/Http/Model/UserRecharge.php @@ -16,6 +16,7 @@ class UserRecharge extends BaseModel */ protected $guarded = array(); + const UN_PAY = 0; const COMPLETE_PAY = 1; //获取列表 diff --git a/resources/views/weixin/user/userRecharge.blade.php b/resources/views/weixin/user/userRecharge.blade.php index 7cba2f3..a1df75d 100644 --- a/resources/views/weixin/user/userRecharge.blade.php +++ b/resources/views/weixin/user/userRecharge.blade.php @@ -19,6 +19,7 @@