Browse Source

修改微信公众号类

chenbo 4 years ago
parent
commit
0591b0e50e

+ 3 - 1
_sql/fission.sql

@@ -3,7 +3,7 @@
 -- https://www.phpmyadmin.net/
 --
 -- 主机: localhost
+-- 生成日期: 2021-03-23 19:37:08
 -- 服务器版本: 5.5.62-log
 -- PHP 版本: 5.6.40
 
@@ -31,7 +31,8 @@ SET time_zone = "+00:00";
 CREATE TABLE `fission_baseconfig` (
   `baseconfig_id` int(11) NOT NULL COMMENT 'id',
   `baseconfig_key` varchar(100) DEFAULT NULL COMMENT '键名',
-  `baseconfig_value` varchar(200) DEFAULT NULL COMMENT '键值'
+  `baseconfig_value` varchar(200) DEFAULT NULL COMMENT '键值',
+  `baseconfig_addtime` int(11) DEFAULT NULL COMMENT '添加时间'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
 -- --------------------------------------------------------

+ 1 - 2
config_develop.inc.php

@@ -19,7 +19,7 @@ date_default_timezone_set('PRC');              //时区设置,服务器放置
 session_start();
 //ob_start();
 define("PROJECTCODE",    'ZhimaPHP_fission');          //项目编号,建议修改,每个项目应该不同
-$HTTP_PATH = 'https://fission.xazhima.com/';     //网站访问路径,根据实际情况修改,务必以“/”结尾。
+$HTTP_PATH = 'http://fission.xazhima.com/';     //网站访问路径,根据实际情况修改,务必以“/”结尾。
 
 //数据库连接参数设置=======================================
 $DB_host   = 'localhost';                      //数据库地址
@@ -33,5 +33,4 @@ $DB_prefix = 'fission_';
 $DB_DEBUG_LEVEL = 0;
 
 
-
 ?>

+ 0 - 2
config_online.inc.php

@@ -33,6 +33,4 @@ $DB_prefix = 'fission_';
 $DB_DEBUG_LEVEL = 0;
 
 
-
-
 ?>

+ 0 - 272
lib/common/weixin.class.php

@@ -1,272 +0,0 @@
-
-<?php
-/**
- * 微信支付服务器端下单
- * 微信APP支付文档地址:  https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_6
- * 使用示例
- *  构造方法参数
- *      'appid'     =>  //填写微信分配的公众账号ID
- *      'mch_id'    =>  //填写微信支付分配的商户号
- *      'notify_url'=>  //填写微信支付结果回调地址
- *      'key'       =>  //填写微信商户支付密钥
- *  );
- *  统一下单方法
- *  $WechatAppPay = new wechatAppPay($options);
- *  $params['body'] = '商品描述';                   //商品描述
- *  $params['out_trade_no'] = '1217752501201407';   //自定义的订单号,不能重复
- *  $params['total_fee'] = '100';                   //订单金额 只能为整数 单位为分
- *  $params['trade_type'] = 'APP';                  //交易类型 JSAPI | NATIVE |APP | WAP
- *  $wechatAppPay->unifiedOrder( $params );
- */
-class weixin
-{
-
-    private $appid;
-    private $seceret;
-
-
-    public function __construct($appid, $seceret)
-    {
-        $this->appid = $appid;
-        $this->seceret = $seceret;
-    }
-
-
-    /**
-     * code获取openid
-     * @param $code
-     * @return mixed
-     */
-    public function code2Session($code)
-    {
-        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appid}&secret={$this->seceret}&js_code={$code}&grant_type=authorization_code";
-
-        $res = Curl::get($url,true);
-
-        return json_decode($res,true);
-    }
-
-
-    public function getAccessToken()
-    {
-        $rs = Baseconfig::getInfoByKey(TOKEN_BASE_KEY);
-
-        if (empty($rs) || (time() - $rs["lastupdate"]) > TOKEN_LIMIT_TIME) {
-            $accessToken = self::refreshToken();
-        } else {
-            $accessToken = $rs["value"];
-        }
-        return $accessToken;
-    }
-
-
-
-    public function refreshToken()
-    {
-        $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->seceret;
-        $res = file_get_contents($token_access_url); //
-        $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量s
-        $access_token = $result['access_token'];
-
-        $rs = Baseconfig::getInfoByKey(TOKEN_BASE_KEY);
-        if ($rs) {
-            $res = Baseconfig::updateByKey(TOKEN_BASE_KEY, array("value" => $access_token, "lastupdate" => time()));
-        } else {
-            $attrs = array(
-                "key"=>TOKEN_BASE_KEY,
-                "value"=>$access_token,
-                "name"=>"token"
-            );
-            $res = Baseconfig::add($attrs);
-        }
-        if ($res) {
-            return $access_token;
-        }
-    }
-
-
-
-    public function createBase64($path,$scene)
-    {
-        $accessToken = $this->getAccessToken();
-        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken}";
-
-//        if(!file_exists(FILE_PATH.$destPath))
-//        {
-//            mkdir(FILE_PATH.$destPath,0777,true);
-//        }
-
-//        $fileName = date("YmdHis").randcode(4).".jpg";
-
-        $resData = Curl::post($url,json_encode(array("page"=>$path,"scene"=>$scene)));
-
-
-        return Image::BinaryToBase64($resData);
-
-
-//        file_put_contents(FILE_PATH.$destPath.$fileName,$resData);
-
-
-    }
-
-
-    public function createQrCode($path,$scene,$destPath)
-    {
-        $accessToken = $this->getAccessToken();
-        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken}";
-
-        if(!file_exists(FILE_PATH.$destPath))
-        {
-            mkdir(FILE_PATH.$destPath,0777,true);
-        }
-
-        $fileName = date("YmdHis").randcode(4).".jpg";
-
-        $resData = Curl::post($url,json_encode(array("page"=>$path,"scene"=>$scene)));
-
-
-
-        file_put_contents(FILE_PATH.$destPath.$fileName,$resData);
-
-        return $destPath.$fileName;
-
-    }
-
-
-    public function sendBaomingInform($openId,$formId,$page,$name,$title){
-        $accessToken = $this->getAccessToken();
-        $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$accessToken}";
-
-        $time = date("Y-m-d H:i:s");
-
-        $data = '{
-                  "touser": "'.$openId.'",
-                  "template_id": "'.BAOMING_TEMPLATE_ID.'",
-                  "page": "'.$page.'",
-                  "form_id": "'.$formId.'",
-                  "data": {
-                      "keyword1": {
-                          "value": "'.$name.'"
-                      },
-                      "keyword2": {
-                          "value": "'.$title.'"
-                      },
-                      "keyword3": {
-                          "value": "'.$time.'"
-                      }
-                  }
-                }';
-
-
-
-        $rs = Curl::post($url,$data);
-
-
-    }
-
-
-    public function sendSignSuccess($openId,$formId,$page,$name,$title){
-        $accessToken = $this->getAccessToken();
-        $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$accessToken}";
-
-        $time = date("Y-m-d H:i:s");
-
-        $data = '{
-                  "touser": "'.$openId.'",
-                  "template_id": "'.SIGN_SUCCESS_TEMPLATE_ID.'",
-                  "page": "'.$page.'",
-                  "form_id": "'.$formId.'",
-                  "data": {
-                      "keyword1": {
-                          "value": "'.$name.'"
-                      },
-                      "keyword2": {
-                          "value": "'.$time.'"
-                      },
-                      "keyword3": {
-                          "value": "'.$title.'"
-                      }
-                  }
-                }';
-
-
-
-        $rs = Curl::post($url,$data);
-
-
-    }
-
-
-
-    /***发送动开始通知 订阅消息***/
-    public function sendBeginInform($openId,$page,$auth,$title,$time,$address){
-        $accessToken = $this->getAccessToken();
-        $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$accessToken}";
-
-
-        $data = '{
-                  "touser": "'.$openId.'",
-                  "template_id": "'.BAOMING_BEGIN_INFORM_TEMPLATE_ID.'",
-                  "page": "'.$page.'",
-                  "data": {
-                      "name1": {
-                          "value": "'.$auth.'"
-                      },
-                      "thing4": {
-                          "value": "'.$title.'"
-                      },
-                      "date5": {
-                          "value": "'.$time.'"
-                      },
-                      "thing6": {
-                          "value": "'.$address.'"
-                      }
-                  }
-                }';
-
-
-
-        $rs = Curl::post($url,$data);
-
-
-
-
-    }
-
-
-    /***发送奖品通知 订阅消息***/
-    public function sendAwardInform($openId,$page,$auth,$title,$phone,$awardName){
-        $accessToken = $this->getAccessToken();
-        $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$accessToken}";
-
-
-        $data = '{
-                  "touser": "'.$openId.'",
-                  "template_id": "'.BAOMING_AWARD_INFORM_TEMPLATE_ID.'",
-                  "page": "'.$page.'",
-                  "data": {
-                      "thing1": {
-                          "value": "'.$title.'"
-                      },
-                      "thing2": {
-                          "value": "'.$awardName.'"
-                      },
-                      "phone_number3": {
-                          "value": "'.$phone.'"
-                      },
-                      "name4": {
-                          "value": "'.$auth.'"
-                      }
-                  }
-                }';
-
-
-
-        $rs = Curl::post($url,$data);
-
-
-    }
-
-
-
-}

+ 88 - 0
lib/common/weixin_public.class.php

@@ -0,0 +1,88 @@
+
+<?php
+/**
+ * 微信支付服务器端下单
+ * 微信APP支付文档地址:  https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_6
+ * 使用示例
+ *  构造方法参数
+ *      'appid'     =>  //填写微信分配的公众账号ID
+ *      'mch_id'    =>  //填写微信支付分配的商户号
+ *      'notify_url'=>  //填写微信支付结果回调地址
+ *      'key'       =>  //填写微信商户支付密钥
+ *  );
+ *  统一下单方法
+ *  $WechatAppPay = new wechatAppPay($options);
+ *  $params['body'] = '商品描述';                   //商品描述
+ *  $params['out_trade_no'] = '1217752501201407';   //自定义的订单号,不能重复
+ *  $params['total_fee'] = '100';                   //订单金额 只能为整数 单位为分
+ *  $params['trade_type'] = 'APP';                  //交易类型 JSAPI | NATIVE |APP | WAP
+ *  $wechatAppPay->unifiedOrder( $params );
+ */
+class weixin_public
+{
+
+    private $appid;
+    private $seceret;
+    private $uri;
+
+    public function __construct($appid, $seceret, $uri)
+    {
+        $this->appid = $appid;
+        $this->seceret = $seceret;
+        $this->uri = $uri;
+    }
+
+    //获取code
+    public function redirectWithCode()
+    {
+        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid
+            ."&redirect_uri=".$this->uri
+            ."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
+
+        header('Location: '.$url);
+        exit;
+    }
+
+
+    public function getAccessToken()
+    {
+        $rs = Baseconfig::getInfoByKey(TOKEN_BASE_KEY);
+
+        if (empty($rs) || (time() - $rs["lastupdate"]) > TOKEN_LIMIT_TIME) {
+            $accessToken = self::refreshToken();
+        } else {
+            $accessToken = $rs["value"];
+        }
+        return $accessToken;
+    }
+
+
+
+    public function refreshToken()
+    {
+        $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->seceret;
+        $res = file_get_contents($token_access_url); //
+        $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量s
+        $access_token = $result['access_token'];
+
+        $rs = Baseconfig::getInfoByKey(TOKEN_BASE_KEY);
+        if ($rs) {
+            $res = Baseconfig::updateByKey(TOKEN_BASE_KEY, array("value" => $access_token, "lastupdate" => time()));
+        } else {
+            $attrs = array(
+                "key"=>TOKEN_BASE_KEY,
+                "value"=>$access_token,
+                "name"=>"token"
+            );
+            $res = Baseconfig::add($attrs);
+        }
+        if ($res) {
+            return $access_token;
+        }
+    }
+
+
+
+
+
+}

+ 0 - 70
lib/common/wxbizdatacrypt.php

@@ -1,70 +0,0 @@
-<?php
-
-/**
- * 对微信小程序用户加密数据的解密示例代码.
- *
- * @copyright Copyright (c) 1998-2014 Tencent Inc.
- */
-
-class wxbizdatacrypt
-{
-    private $appid;
-	private $sessionKey;
-    public static $OK = 0;
-    public static $IllegalAesKey = -41001;
-    public static $IllegalIv = -41002;
-    public static $IllegalBuffer = -41003;
-    public static $DecodeBase64Error = -41004;
-
-	/**
-	 * 构造函数
-	 * @param $sessionKey string 用户在小程序登录后获取的会话密钥
-	 * @param $appid string 小程序的appid
-	 */
-	public function __construct( $appid, $sessionKey)
-	{
-		$this->sessionKey = $sessionKey;
-		$this->appid = $appid;
-	}
-
-
-	/**
-	 * 检验数据的真实性,并且获取解密后的明文.
-	 * @param $encryptedData string 加密的用户数据
-	 * @param $iv string 与用户数据一同返回的初始向量
-	 * @param $data string 解密后的原文
-     *
-	 * @return int 成功0,失败返回对应的错误码
-	 */
-	public function decryptData( $encryptedData, $iv, &$data )
-	{
-		if (strlen($this->sessionKey) != 24) {
-			return self::$IllegalAesKey;
-		}
-		$aesKey=base64_decode($this->sessionKey);
-
-        
-		if (strlen($iv) != 24) {
-			return self::$IllegalIv;
-		}
-		$aesIV=base64_decode($iv);
-
-		$aesCipher=base64_decode($encryptedData);
-
-		$result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
-
-		$dataObj=json_decode( $result );
-		if( $dataObj  == NULL )
-		{
-			return self::$IllegalBuffer;
-		}
-		if( $dataObj->watermark->appid != $this->appid )
-		{
-			return self::$IllegalBuffer;
-		}
-		$data = $result;
-		return self::$OK;
-	}
-
-}
-

+ 3 - 0
lib/table/table_baseconfig.class.php

@@ -25,6 +25,7 @@ class Table_baseconfig extends Table
         $attr['id']    = 'baseconfig_id';
         $attr['key']   = 'baseconfig_key';
         $attr['value'] = 'baseconfig_value';
+        $attr['addtime'] = 'baseconfig_addtime';
 
         return $attr;
     }
@@ -53,6 +54,7 @@ class Table_baseconfig extends Table
         $param = array(
             'baseconfig_key'   => array('string', $attr['key']),
             'baseconfig_value' => array('string', $attr['value']),
+            'baseconfig_addtime' => array('number', time()),
         );
 
         return $this->pdo->sqlinsert($this->table_fullname, $param);
@@ -63,6 +65,7 @@ class Table_baseconfig extends Table
         $param = array(
             'baseconfig_key'   => array('string', $attr['key']),
             'baseconfig_value' => array('string', $attr['value']),
+            'baseconfig_addtime' => array('number', time()),
         );
 
         $where = array(

+ 7 - 3
setting.inc.php

@@ -49,13 +49,17 @@ function GetArrValByKey($arr, $key) {
 
 //性别
 $globalSexList = array(
-    0 => '女',
     1 => '男',
+    2 => '女',
 );
 
 
-//权限
-define("AUTH_ADMIN", 7001);                //超级管理员
+define('APPID', 'wxa6a88eafe691d79b');
+define('APPSECRET', 'ef2d5da2cd8ca534da1a81f940806146');
+define('APPURI', 'http://fission.xazhima.com/front-page/fission-page.html');
+
+define('BASE_KEY_ACCESS_TOKEN', 'access_token');
+define('BASE_KEY_REFRESH_TOKEN', 'refresh_token');
 
 
 ?>