Example #1
0
 /**
  * 构造方法,用于实例化微信SDK
  * 自动回复消息时实例化该SDK
  * @param string $token 微信后台填写的TOKEN
  * @param string $appid 微信APPID (安全模式和兼容模式有效)
  * @param string $key 消息加密KEY (EncodingAESKey)
  * @throws \Exception
  */
 public function __construct($token, $appid = '', $key = '')
 {
     //设置安全模式
     if (isset($_GET['encrypt_type']) && $_GET['encrypt_type'] == 'aes') {
         self::$msgSafeMode = true;
     }
     //参数验证
     if (self::$msgSafeMode) {
         if (empty($key) || empty($appid)) {
             throw new \Exception('缺少参数EncodingAESKey或APP_ID!');
         }
         self::$appId = $appid;
         self::$encodingAESKey = $key;
     }
     //TOKEN验证
     if ($token) {
         self::auth($token) || exit;
         if (IS_GET) {
             exit($_GET['echostr']);
         } else {
             self::$token = $token;
             $this->init();
         }
     } else {
         throw new \Exception('缺少参数TOKEN!');
     }
 }
Example #2
0
 /**
  * 构造方法,用于实例化微信SDK
  * 自动回复消息时实例化该SDK
  * @param string $token 微信后台填写的TOKEN
  * @param string $appid 微信APPID (安全模式和兼容模式有效)
  * @param string $key   消息加密KEY (EncodingAESKey)
  */
 public function __construct($token)
 {
     //设置安全模式
     if (isset($_GET['encrypt_type']) && $_GET['encrypt_type'] == 'aes') {
         self::$msgSafeMode = true;
     }
     //TOKEN验证
     if ($token) {
         self::auth($token) || exit;
         if (IS_GET) {
             exit($_GET['echostr']);
         } else {
             self::$token = $token;
             $this->init();
         }
     } else {
         throw new \Exception('缺少参数TOKEN!');
     }
 }