chenbo hace 4 años
padre
commit
528002a631

+ 25 - 0
api/addcount.php

@@ -0,0 +1,25 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * Member: tianyi
+ * Date: 2018/4/11
+ * Time: 17:42
+ */
+try {
+    $openid = safeCheck($_POST["openid"], 0);
+
+    //检查
+    if (empty($openid)) {
+        echo action_msg('微信opeid不能为空', 101);
+        exit;
+    }
+
+    Reader::addCountByOpenId($openid);
+    $ret = Reader::getInfoByOpenId($openid);
+    echo action_msg($ret, 200);
+
+} catch (MyException $e) {
+    echo action_msg($e->getMessage(), $e->getCode());
+}
+
+?>

+ 0 - 50
api/auth.php

@@ -1,50 +0,0 @@
-
-<?php
-/**
- * Created by PhpStorm.
- * member: tianyi
- * Date: 2018/4/11
- * Time: 17:42
- */
-
-require_once ($LIB_COMMON_PATH."wxbizdatacrypt.php");
-
-
-try{
-
-    $iv = safeCheck($_POST["iv"], 0);
-    $encryptedData = safeCheck($_POST["encryptedData"], 0);
-    $sessionKey = safeCheck($_POST["session_key"], 0);
-    $pc = new wxbizdatacrypt(MINI_APPID, $sessionKey);
-    $errCode = $pc->decryptData($encryptedData, $iv, $data );
-
-    if ($errCode == 0){
-        $dataArr = json_decode($data,true);
-        /*
-         * {
-                "phoneNumber": "13580006666",
-                "purePhoneNumber": "13580006666",
-                "countryCode": "86",
-                "watermark":
-                {
-                    "appid":"APPID",
-                    "timestamp": TIMESTAMP
-                }
-            }
-         *
-         */
-        $ret['phone'] = $dataArr["phoneNumber"];
-        $ret['msg'] = '绑定成功';
-        echo action_msg($ret, 200);
-    }else{
-        throw new MyException("授权失败!",101);
-    }
-
-//    echo action_msg($memberInfo,200);
-    exit;
-
-}catch (MyException $e){
-    echo action_msg($e->getMessage(),$e->getCode());
-}
-
-?>

+ 9 - 24
api/demo/auth.html

@@ -2,7 +2,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>接口6:微信授权</title>
+    <title>接口3:增加分享次数</title>
     <script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
     <script type="text/javascript" src="js/func.common.js"></script>
     <script type="text/javascript" src="js/func.js"></script>
@@ -18,9 +18,8 @@
                 var method = $('input[name="method"]').val();
                 var timestamp =$('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
-                var iv = $('input[name="iv"]').val();
-                var encryptedData = $('input[name="encryptedData"]').val();
-                var session_key = $('input[name="session_key"]').val();
+
+                var openid = $('input[name="openid"]').val();
 
                 $('#sign').val(sign);
                 $.ajax({
@@ -29,9 +28,8 @@
                         method :method,
                         timestamp :timestamp,
                         sign   : sign,
-                        iv   : iv,
-                        encryptedData:encryptedData,
-                        session_key:session_key,
+                        openid  : openid,
+
                     },
                     url : "../api.php",
                     beforeSend :  function(data){
@@ -49,7 +47,7 @@
     </script>
 </head>
 <body>
-<div id="head"><p>接口9:微信授权</p></div>
+<div id="head"><p>接口3:增加分享次数</p></div>
 <div id="content">
     <div id="left">
         <div class ="message"><p>接口返回:</p></div>
@@ -60,29 +58,16 @@
         <form>
             <p>
                 <span>method:</span>
-                <input type="text" class="input-text"  name="method" value="auth"/>
+                <input type="text" class="input-text"  name="method" value="reader_login"/>
             </p>
             <p>
                 <span>timestamp:</span>
                 <input type="text" class="input-text"  name="timestamp" value="11111111"/>
             </p>
 
-
-            <p>
-                <span>iv:</span>
-                <input type="text" class="input-text"  name="iv" value=""/>
-            </p>
-
-
-            <p>
-                <span>encryptedData:</span>
-                <input type="text" class="input-text"  name="encryptedData" value=""/>
-            </p>
-
-
             <p>
-                <span>session_key:</span>
-                <input type="text" class="input-text"  name="session_key" value=""/>
+                <span>openid:</span>
+                <input type="text" class="input-text"  name="openid" value="wxgddsgserrwett"/>
             </p>
 
             <p><button class="button success small" id="btn" type="button">发送请求</button></p>

+ 6 - 13
api/demo/index.html

@@ -23,29 +23,22 @@
         <th class="n2">接口名字</th>
         <th class="n3">查看Demo</th>
         <th class="n4">下载文档</th>
-    <tr class="top">
-        <th class="title" colspan="4">阅读和分享接口</th>
-    </tr>
     <tr>
         <td class="n1">1</td>
-        <td class="n2"><a href="reader_login.html" target="_blank">阅读和分享</a></td>
-        <td class="n3"><a href="reader_login.html" target="_blank">查看Demo</a></td>
+        <td class="n2"><a href="login.html" target="_blank">微信登录</a></td>
+        <td class="n3"><a href="login.html" target="_blank">查看Demo</a></td>
         <td class="n4"><a href="#" target="_blank">下载文档</a></td>
     </tr>
-
-    <tr class="top">
-        <th class="title" colspan="4">微信登录和授权接口</th>
-    </tr>
     <tr>
         <td class="n1">2</td>
-        <td class="n2"><a href="login.html" target="_blank">微信登录</a></td>
-        <td class="n3"><a href="login.html" target="_blank">查看Demo</a></td>
+        <td class="n2"><a href="wxinfo.html" target="_blank">获取微信信息</a></td>
+        <td class="n3"><a href="wxinfo.html" target="_blank">查看Demo</a></td>
         <td class="n4"><a href="#" target="_blank">下载文档</a></td>
     </tr>
     <tr>
         <td class="n1">3</td>
-        <td class="n2"><a href="auth.html" target="_blank">微信授权</a></td>
-        <td class="n3"><a href="auth.html" target="_blank">查看Demo</a></td>
+        <td class="n2"><a href="addcount.html" target="_blank">增加分享次数</a></td>
+        <td class="n3"><a href="addcount.html" target="_blank">查看Demo</a></td>
         <td class="n4"><a href="#" target="_blank">下载文档</a></td>
     </tr>
 

+ 3 - 22
api/demo/login.html

@@ -2,7 +2,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>接口5:微信登录</title>
+    <title>接口1:微信登录</title>
     <script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
     <script type="text/javascript" src="js/func.common.js"></script>
     <script type="text/javascript" src="js/func.js"></script>
@@ -18,14 +18,7 @@
                 var method = $('input[name="method"]').val();
                 var timestamp =$('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
-//                var phone = $('input[name="phone"]').val();
-                var code = $('input[name="code"]').val();
 
-//                var wx_nickname = $('input[name="wx_nickname"]').val();
-//                var wx_sex = $('input[name="wx_sex"]').val();
-//                var wx_head = $('input[name="wx_head"]').val();
-//                var wx_longitude = $('input[name="wx_longitude"]').val();
-//                var wx_latitude = $('input[name="wx_latitude"]').val();
                 $('#sign').val(sign);
                 $.ajax({
                     type         : 'POST',
@@ -33,14 +26,7 @@
                         method :method,
                         timestamp :timestamp,
                         sign   : sign,
-//                        phone   : phone,
-                        code   : code,
-                        // invited:invited
-//                        wx_nickname   : wx_nickname,
-//                        wx_sex   : wx_sex,
-//                        wx_head   : wx_head,
-//                        wx_longitude   : wx_longitude,
-//                        wx_latitude   : wx_latitude
+
                     },
                     url : "../api.php",
                     beforeSend :  function(data){
@@ -58,7 +44,7 @@
     </script>
 </head>
 <body>
-<div id="head"><p>接口8:微信登录</p></div>
+<div id="head"><p>接口1:微信登录</p></div>
 <div id="content">
     <div id="left">
         <div class ="message"><p>接口返回:</p></div>
@@ -76,11 +62,6 @@
                 <input type="text" class="input-text"  name="timestamp" value="11111111"/>
             </p>
 
-            <p>
-                <span>code:</span>
-                <input type="text" class="input-text"  name="code" value="code"/>
-            </p>
-
             <p><button class="button success small" id="btn" type="button">发送请求</button></p>
         </form>
     </div>

+ 7 - 27
api/demo/reader_login.html

@@ -2,7 +2,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>接口1:阅读与分享</title>
+    <title>接口2:获取微信信息</title>
     <script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
     <script type="text/javascript" src="js/func.common.js"></script>
     <script type="text/javascript" src="js/func.js"></script>
@@ -18,11 +18,7 @@
                 var method = $('input[name="method"]').val();
                 var timestamp =$('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
-
-                var phone = $('input[name="phone"]').val();
-                var wxopenid = $('input[name="wxopenid"]').val();
-                var name = $('input[name="name"]').val();
-                var sex = $('input[name="sex"]').val();
+                var code = $('input[name="code"]').val();
 
                 $('#sign').val(sign);
                 $.ajax({
@@ -31,11 +27,7 @@
                         method :method,
                         timestamp :timestamp,
                         sign   : sign,
-                        phone  : phone,
-                        wxopenid  : wxopenid,
-                        name  : name,
-                        sex  : sex,
-
+                        code   : code,
                     },
                     url : "../api.php",
                     beforeSend :  function(data){
@@ -53,7 +45,7 @@
     </script>
 </head>
 <body>
-<div id="head"><p>接口1:阅读与分享</p></div>
+<div id="head"><p>接口2:获取微信信息</p></div>
 <div id="content">
     <div id="left">
         <div class ="message"><p>接口返回:</p></div>
@@ -64,7 +56,7 @@
         <form>
             <p>
                 <span>method:</span>
-                <input type="text" class="input-text"  name="method" value="reader_login"/>
+                <input type="text" class="input-text"  name="method" value="login"/>
             </p>
             <p>
                 <span>timestamp:</span>
@@ -72,20 +64,8 @@
             </p>
 
             <p>
-                <span>phone:</span>
-                <input type="text" class="input-text"  name="phone" value="13900010001"/>
-            </p>
-            <p>
-                <span>wxopenid:</span>
-                <input type="text" class="input-text"  name="wxopenid" value="wxgddsgserrwett"/>
-            </p>
-            <p>
-                <span>name:</span>
-                <input type="text" class="input-text"  name="name" value="张三"/>
-            </p>
-            <p>
-                <span>sex:  0-女  1-男 </span>
-                <input type="text" class="input-text"  name="sex" value="1"/>
+                <span>code:</span>
+                <input type="text" class="input-text"  name="code" value="code"/>
             </p>
 
             <p><button class="button success small" id="btn" type="button">发送请求</button></p>

+ 4 - 26
api/login.php

@@ -6,33 +6,11 @@
  * Time: 17:42
  */
 try {
-    $code = safeCheck($_POST["code"], 0);
-    $weixin = new weixin(MINI_APPID, MINI_APPKEY);
-    $res = $weixin->code2Session($code);
 
-    if (empty($res['openid'])) {
-        echo action_msg($res['errmsg'], 1);
-    } else {
-        $reader = Reader::getInfoByOpenId($res['openid']);
-        if (!empty($reader)) {
-            $ret = Reader::getPassInfo($reader['id']);
-            $ret['openid'] = $res['openid'];
-            $ret['session_key'] = $res['session_key'];
-            echo action_msg($ret, 200);
-            exit;
-        } else {
-            //返回需要登录提示
-            $ret['id'] = 0;
-            $ret['type'] = 3;    //3-客户不存在,需要登录
-            $ret['code'] = '';
-            $ret['pass'] = 0;
-            $ret['msg'] = '需要授权登录';
-            $ret['openid'] = $res['openid'];
-            $ret['session_key'] = $res['session_key'];
-            echo action_msg($ret, 200);
-            exit;
-        }
-    }
+    $weixin_public = new weixin_public(APPID, APPSECRET, APPURI);
+    $weixin_public->redirectWithCode();
+    exit;
+
 } catch (MyException $e) {
     echo action_msg($e->getMessage(), $e->getCode());
 }

+ 0 - 57
api/reader_login.php

@@ -1,57 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * Member: tianyi
- * Date: 2018/4/11
- * Time: 17:42
- */
-try {
-    $phone = safeCheck($_POST["phone"], 0);
-    $wxopenid = safeCheck($_POST["wxopenid"], 0);
-    $name = safeCheck($_POST["name"], 0);
-    $sex = safeCheck($_POST["sex"], 0);
-
-    //检查
-    if (!ParamCheck::is_mobile($phone)) {
-        echo action_msg('电话号码格式错误', 101);
-        exit;
-    }
-    if (empty($name)) {
-        echo action_msg('请填写昵称', 102);
-        exit;
-    }
-    if (!in_array($sex, array(0, 1))) {
-        echo action_msg('性别错误', 103);
-        exit;
-    }
-    if (empty($wxopenid)) {
-        echo action_msg('微信opeid不能为空', 104);
-        exit;
-    }
-
-    //添加不存在的客户
-    $reader = Reader::getInfoByPhone($phone);
-    if (empty($reader)) {
-        //增加新用户
-        $attr['phone'] = $phone;
-        $attr['wxopenid'] = $wxopenid;
-        $attr['name'] = $name;
-        $attr['sex'] = $sex;
-
-        $id = Reader::add($attr);
-        if (empty($id)) {
-            echo action_msg('新增读者失败', 103);
-            exit;
-        }
-    } else {
-        $id = $reader['id'];
-    }
-
-    $ret = Reader::getPassInfo($id);
-    echo action_msg($ret, 200);
-
-} catch (MyException $e) {
-    echo action_msg($e->getMessage(), $e->getCode());
-}
-
-?>

+ 30 - 0
api/wxinfo.php

@@ -0,0 +1,30 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * Member: tianyi
+ * Date: 2018/4/11
+ * Time: 17:42
+ */
+try {
+    $code = safeCheck($_POST["code"], 0);
+    $weixin_public = new weixin_public(APPID, APPSECRET, APPURI);
+    $info = $weixin_public->getAllInfo($code);
+
+    if (empty($info['openid'])) {
+        echo action_msg($info['errmsg'], 1);
+        exit;
+    } else {
+        $attr = Reader::getInfoByOpenId($info['openid']);
+        if (empty($attr)) {
+            Reader::add($attr);
+        } else {
+            Reader::update($attr['id'], $info);
+        }
+        echo action_msg($info, 200);
+        exit;
+    }
+} catch (MyException $e) {
+    echo action_msg($e->getMessage(), $e->getCode());
+}
+
+?>

+ 2 - 2
lib/reader.class.php

@@ -38,10 +38,10 @@ class Reader{
         return $Table_reader->update($id, $attrs);
     }
 
-    static public function addCount($id)
+    static public function addCountByOpenId($openId)
     {
         $Table_reader = new Table_reader();
-        return $Table_reader->addCount($id);
+        return $Table_reader->addCountByOpenId($openId);
     }
 
     static public function del($id)

+ 2 - 2
lib/table/table_reader.class.php

@@ -93,7 +93,7 @@ class Table_reader extends Table
         return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
     }
 
-    public function addCount($id)
+    public function addCountByOpenId($openId)
     {
         $param = array(
             'reader_addtime'    => array('number', time()),
@@ -101,7 +101,7 @@ class Table_reader extends Table
         );
 
         $where = array(
-            'reader_id' => array('number', $id)
+            'reader_openid' => array('string', $openId)
         );
 
         return $this->pdo->sqlupdate($this->table_fullname, $param, $where);