Example #1
0
 public static function getqrcode()
 {
     global $_G;
     if (!$_G['wechat']['setting']) {
         $_G['wechat']['setting'] = unserialize($_G['setting']['mobilewechat']);
     }
     require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
     $wechat_client = new WeChatClient($_G['wechat']['setting']['wechat_appId'], $_G['wechat']['setting']['wechat_appsecret']);
     $ticket = '';
     if (!$_G['cookie']['wechat_ticket'] || $_G['wechat']['setting']['wechat_mtype'] == 1) {
         $code = 0;
         $i = 0;
         do {
             $code = rand(100000, 999999);
             $codeexists = C::t('#wechat#mobile_wechat_authcode')->fetch_by_code($code);
             $i++;
         } while ($codeexists && $i < 10);
         if ($_G['wechat']['setting']['wechat_mtype'] == 2) {
             $option = array('scene_id' => $code, 'expire' => self::$QRCODE_EXPIRE, 'ticketOnly' => '1');
             $ticket = $wechat_client->getQrcodeTicket($option);
             if (!$ticket) {
                 showmessage('wechat:wechat_message_codefull');
             }
             dsetcookie('wechat_ticket', authcode($ticket . "\t" . $code, 'ENCODE'), self::$QRCODE_EXPIRE);
         }
     } else {
         list($ticket, $code) = explode("\t", authcode($_G['cookie']['wechat_ticket'], 'DECODE'));
     }
     $isqrapi = $ticket ? $ticket : '';
     if ($codeexists) {
         showmessage('wechat:wechat_message_codefull');
     }
     $qrcodeurl = !$isqrapi ? $_G['setting']['attachurl'] . 'common/' . $_G['wechat']['setting']['wechat_qrcode'] : $_G['siteurl'] . 'plugin.php?id=wechat:qrcode&rand=' . random(5);
     $codeenc = urlencode(base64_encode(authcode($code, 'ENCODE', $_G['config']['security']['authkey'])));
     C::t('#wechat#mobile_wechat_authcode')->insert(array('sid' => $_G['cookie']['saltkey'], 'uid' => $_G['uid'], 'code' => $code, 'createtime' => TIMESTAMP), 0, 1);
     if (!discuz_process::islocked('clear_wechat_authcode')) {
         C::t('#wechat#mobile_wechat_authcode')->delete_history();
         discuz_process::unlock('clear_wechat_authcode');
     }
     return array($isqrapi, $qrcodeurl, $codeenc, $code);
 }
    showtableheader();
    showsubmit('settingsubmit');
    showtablefooter();
    showformfooter();
} else {
    if ($_GET['setting']['wechat_mtype'] == 2 && !$_GET['setting']['wechat_appId']) {
        cpmsg(lang('plugin/wechat', 'wechat_at_need'), '', 'error');
    }
    if ($_GET['setting']['wechat_appId'] && $_GET['setting']['wechat_appsecret']) {
        require_once DISCUZ_ROOT . './source/plugin/wechat/wechat.lib.class.php';
        $wechat_client = new WeChatClient($_GET['setting']['wechat_appId'], $_GET['setting']['wechat_appsecret']);
        if (!$wechat_client->getAccessToken(1, 1)) {
            cpmsg(lang('plugin/wechat', 'wechat_at_geterror'), '', 'error');
        }
        $option = array('scene_id' => 100000, 'expire' => 30, 'ticketOnly' => 1);
        $ticket = $wechat_client->getQrcodeTicket($option);
        if (!$wechat_client->getQrcodeImgUrlByTicket($ticket)) {
            cpmsg(lang('plugin/wechat', 'wechat_at_qrgeterror'), '', 'error');
        }
    }
    $_GET['setting']['wechat_qrtype'] = !$_GET['setting']['wechat_mtype'] ? 3 : 0;
    $_GET['setting']['wechat_token'] = $_GET['setting']['wechat_token'] ? $_GET['setting']['wechat_token'] : random(16);
    if ($_FILES['wechat_qrcode']['tmp_name']) {
        $upload = new discuz_upload();
        if (!$upload->init($_FILES['wechat_qrcode'], 'common', random(3, 1), random(8)) || !$upload->save()) {
            cpmsg($upload->errormessage(), '', 'error');
        }
        $_GET['setting']['wechat_qrcode'] = $upload->attach['attachment'];
    }
    if ($setting['wsq_siteid']) {
        $siteinfo = wsq::edit($setting['wsq_sitename'], $setting['wsq_siteurl'], $setting['wsq_sitelogo'], $setting['wsq_sitesummary'], $_GET['setting']['wechat_mtype'], $_GET['setting']['wechat_qrtype']);