1, 'msg' => "手机号 不能为空"];// 商户私钥文件路径。// if (empty($post['phone'])||empty($post['code'])) return jsonFail("请求参数错误");_微信支付 op">
赞
踩
- <?php
- namespace app\api\controller;
-
- use alisms\SendSms;
- use app\index\controller\Api;
- use think\Controller;
- use think\Db;
- use think\Request;
- //use wxappletpay\Pay;
- use think\Exception;
- use GuzzleHttp\Exception\RequestException;
- use WechatPay\GuzzleMiddleware\WechatPayMiddleware;
- use WeChatPay\Util\PemUtil;
- //use GuzzleHttp\HandlerStack;
- use GuzzleHttp\HandlerStack;
- //use WechatPay\GuzzleMiddleware\Util\AesUtil;
-
- class WxApplet extends Controller
- {
- public function __construct()
- {
- // $result=$this->verifyPermissions();
- // if (!$result){
- // die(json_encode(['code'=>40010,'errmsg'=>'权限不足']));
- // }
-
-
- }
-
-
-
- private function verifyPermissions()
- {
- $token = Request::instance()->header('token');
- return redis()->exists($token);
- }
-
- public function cardList(){
- $cardList=db('cardinfo')->select();
- return jsonSuccess($cardList);
- }
-
- //简单的调用
- public function sendSms(Request $request)
- {
- //判断是否ajax提交
- if($request->isPost())
- {
- //获取mobile参数
- $mobile = $request->param('phone');
- if(!preg_match("/^1[3456789]\d{9}$/", $mobile)){
- return jsonFail("手机号不正确");
- }
- //新建code
- $templateParam = array('code' => rand(10000,99999));
-
- //保存在session进行验证
- session('sms_code',['mobile'=>$mobile,'code'=>$templateParam['code']]);
-
- //实例化类
- $send = new SendSms();
- //调用类里面send方法 send()方法需要俩个参数;
- //发送短信~
- $result = $send->send($mobile,$templateParam,config('AliSms.payTemplateCode'));
- //是否成功
- if($result)
- {
- //返回
- return jsonSuccess('','发送成功!');
- }else{
- return jsonFail("发送短信失败");
- }
- }
- }
-
- public function verifyFaces(){
- $api = new Api();
- header("Access-Control-Allow-Origin: *");
-
- if (request()->isPost()) {
- //1。上传图片方式
- $farr = $api->upload("faces");
- $img_dir = ROOT_PATH . 'public' . DS . 'uploads' . DS . $farr['save'];
- $img_base64 = $api->imgToBase64($img_dir);
- $param['image'] = substr($img_base64, 22);
- //2。base64字符串形式
- // $img_base64 = input("post.faces");
- // $param['image'] = $img_base64;
- // return jsonSuccess(['picPath'=>DS . 'uploads' . DS . $farr['save']],"通过");
- // $membernum = input("post.membernum")?input("post.membernum"):1;
- $membernum=1;
- $url = "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=" . $api->getbdtoken();
-
-
- $param['image_type'] = "BASE64";
- $param['face_type'] = "LIVE";
- $param['face_field'] = "eye_status,quality,glasses,angle,beauty,expression,mask";
- $param['max_face_num'] = 10;
- // var_dump($param['image']);
- // exit();
- $o = "";
- foreach ($param as $k => $v) {
- $o .= "$k=" . urlencode($v) . "&";
- }
- $post_data = substr($o, 0, -1);
- // var_dump($post_data);
- // exit();
- $res = $api->request_post($url, $post_data);
-
- $res = json_decode($res);
-
-
- if ($res->error_code === 0) {
- if($res->result->face_num!=$membernum){
- return jsonFail("人脸数量不一致");
- }
- $result = $api->face_pic_check($res);
- $picPath = DS . 'uploads' . DS . $farr['save'];
- if ($result['error_code']===0){
- return jsonSuccess($picPath);
- }else{
- return jsonFail($result['error_msg']);
- }
-
- } else {
- return jsonFail($res->error_msg,'',$res->error_code);
- }
-
- // return json_encode($arr, JSON_UNESCAPED_UNICODE);
- }else{
- return jsonFail("非法请求");
- }
- }
-
- public function uploadTmpPic()
- {
- // 获取表单上传文件 例如上传了001.jpg
- $file = request()->file("faces");
- // 移动到框架应用根目录/public/uploads/ 目录下
- $dirPath = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'tmp';
- if (!is_dir($dirPath)){
- mkdir(iconv("UTF-8", "GBK", $dirPath),0777,true);
- }
- $info = $file->move($dirPath);
- // $info = $file->move(ROOT_PATH . 'uploads');
-
- if ($info) {
- // 成功上传后 获取上传信息
- // 输出 jpg
- $upload['houzhui'] = $info->getExtension();
- // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
- $upload['save'] = $info->getSaveName();
- // 输出 42a79759f284b767dfcb2a0197904287.jpg
- $upload['name'] = $info->getFilename();
- } else {
- // 上传失败获取错误信息
- $upload['error'] = $file->getError();
- }
- return jsonSuccess($upload);
- }
-
- public function verifyCode(){
- $post = input('post.');
- $sms_code = session("sms_code");
- // if (empty($post['phone'])||empty($post['code'])) return jsonFail("请求参数错误");
- // if (empty($sms_code)) return jsonFail("session不存在");
- // trace(request()->url().":".json_encode($sms_code), 'api');
- // if($sms_code['mobile']!=$post['phone']) return jsonFail("手机号不正确");
- // if($sms_code['code']!=$post['code']) return jsonFail("验证码不正确");
- return jsonSuccess();
-
- }
-
- public function addCard(){
- $post = input('post.');
- trace(request()->url().":".json_encode($post), 'api');
- if (!is_array($post['username'])) return jsonFail('username必须是Array');
- if (!is_array($post['phone'])) return jsonFail('phone必须是Array');
- if (!is_array($post['shenfenz'])) return jsonFail('shenfenz必须是Array');
- if (!is_array($post['photo'])) return jsonFail('photo必须是Array');
-
- if(empty($post['cardid'])||empty($post['starttime'])||empty($post['endtime'])){
- return json(['code' => 1, "msg" => "cardid,starttime,endtime 不能为空"]);
- }
- // return false;
- $data['cardid'] = $post['cardid'];
- $data['startdate'] = $post['starttime'];
- $data['enddate'] = $post['endtime'];
- $data['pay_way'] = isset($post['pay_way'])?$post['pay_way']:2;
- $data['pay_fee'] = db('cardinfo')->where('cardid',$post['cardid'])->value("cardamt");
- $data['card_type']=$post['card_type'];
- $data['photo']=null;
- $data['client'] = input("post.openid");
-
- $ret=Db::transaction(function () use ($post, $data) {
- try {
- $getid = db('clubinfo')->insertGetId($data);
- $push_data=db('clubinfo')->where('cardno', $getid)->find();
- for ($i = 0; $i < count($post['photo']); $i++) {
- if (empty($post['photo'][$i])||empty($post['username'][$i])){
- return ['code' => 1, 'msg' => "photo,username 不能为空"];
- }
- if ($i===0){
- if ($post['cardid']!=1&&$post['cardid']!=5){
- if (empty($post['shenfenz'][$i])) return ['code' => 1, 'msg' => "身份证号 不能为空"];
- }
-
- if (empty($post['phone'][$i])) return ['code' => 1, 'msg' => "手机号 不能为空"];
- }
- if (!empty($post['shenfenz'][$i])){
- if(preg_match("/([\x81-\xfe][\x40-\xfe])/", $post['shenfenz'][$i], $match)){
- return ['code' => 1, 'msg' => "身份证号不能有中文"];
- }
- }
- if (!empty($post['phone'][$i])){
- if(!is_numeric($post['phone'][$i])){
- return ['code' => 1, 'msg' => "手机号必须是数字"];
- }
- }
-
- $data2 = [];
- $data2['cardno'] = $getid;
- $data2['membername'] = $post['username'][$i];
- $data2['phone'] = isset($post['phone'][$i])?$post['phone'][$i]:"";
- $data2['idnumber'] = isset($post['shenfenz'][$i])?$post['shenfenz'][$i]:"";
- $data2['memberbirthday'] = empty($data2['idnumber']) ? "" : substr($data2['idnumber'], 6, 8);
- $data2['photo'] = $post['photo'][$i];
- $data2['client'] = $data['client'];
- $data2['issub'] = ($i === 0) ? 0 : 1;
- $memberid=db('memberinfo')->insertGetId($data2);
- $data3=db('memberinfo')->where('id', $memberid)->find();
- $push_data['member'][$i] = $data3;
- }
-
-
- return ['code'=>0,"msg"=>"添加成功",'data'=>['cardno'=>$getid]];
- } catch (Exception $e) {
- trace(request()->url().":".$e->getMessage(), 'api');
- return ['code'=>1,"msg"=>"添加失败"];
- }
- });
-
- if (isset($ret['data']['cardno'])){
- $data10['cardno'] = $ret['data']['cardno'];
- $clubInfo=db('clubinfo')->where('cardno', $data10['cardno'])->find();
- $data10['pay_fee'] = $clubInfo['pay_fee'];
- $data10['client'] = $data['client'];
- $data10['order_no'] = 'wx' . time() . $data10['cardno'] ;
- $resultId=db('order')->insertGetId($data10);
- if ($resultId) {
- return jsonSuccess($resultId);
- } else {
- return jsonFail("添加支付数据失败");
- }
- } else {
- return jsonFail("添加年卡数据失败,err:".json_encode($ret));
- }
-
- }
-
- public function getCardInfo(){
- $cardNo = input('post.cardno');
- if (!empty($cardNo)){
- $cardInfo=db('clubinfo')->where('cardno', $cardNo)->find();
- if ($cardInfo){
- return jsonSuccess($cardInfo);
-
- }else{
- return jsonFail();
- }
- }else{
- return jsonFail();
- }
- }
- protected function getsign($data, $appid ,$keypath){
- // $content = $appid . '\n'. $data['timeStamp'] . '\n'. $data['nonceStr'] . '\n'. $data['package'] . '\n';
- // var_dump($content);
- $key = openssl_get_privatekey($keypath);
- // $key = openssl_pkey_get_private($keypath);
- openssl_sign($content, $signature, $key, "SHA256");
- openssl_sign($content, $signature, $key, 'sha256WithRSAEncryption');
- openssl_sign($content, $signature, $key, OPENSSL_ALGO_SHA256);
- // openssl_sign($content, $signature, $key);
- // openssl_free_key($key);
- // $sign = base64_encode($signature);
- // return $sign;
- $str = "{$appid}\n{$data['timeStamp']}\n{$data['nonceStr']}\n{$data['package']}\n";
- $privateKey = PemUtil::loadPrivateKey($keypath); // $this->private_key
- openssl_sign($str, $encrypt_data, openssl_pkey_get_private($privateKey), 'sha256WithRSAEncryption');
- $encrypt_data = base64_encode($encrypt_data);
- return $encrypt_data;
-
- }
-
- public function pay()
- {
- $openid = input('post.openid'); //opendi可以自己重新获取也可以存起来 必须要!!!
- $orderid = input('post.orderid'); //这里是订单的id 根据自己需要来
- // echo date('Y-m-d\TH:i:sP');
- // echo date('c'); die();
- //查询里面的价格
- $orderdata = db('order')->where('id',$orderid)->field('order_no,pay_fee')->find();
- if (is_null($orderdata) ){
- $orderdata = db('order')->where('order_no',$orderid)->field('order_no,pay_fee')->find();
- }
- //引入支付的类 第二个代码块声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/266837推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。