コード例 #1
0
 public function wx_sendMsg($data)
 {
     if (!getglobal('setting/CorpID') || !getglobal('setting/CorpSecret')) {
         return false;
     }
     $user = C::t('user')->fetch($data['uid']);
     if (!$user['wechat_userid'] || $user['wechat_status'] != 1) {
         C::t('notification')->update($data['id'], array('wx_new' => $data['wx_new'] + 1));
         return false;
     }
     $agentid = 0;
     if ($data['from_idtype'] == 'app' && $data['from_id'] && ($wxapp = C::t('wx_app')->fetch($data['from_id']))) {
         if ($wxapp['agentid'] && $wxapp['status'] < 1) {
             $agentid = $wxapp['agentid'];
         }
     }
     $wx = new qyWechat(array('appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret')));
     $msg = array("touser" => "dzz-" . $data['uid'], "safe" => 0, "agentid" => $agentid, "msgtype" => "news", "news" => array("articles" => array(array("title" => $data['title'], "description" => getstr($data['wx_note'], 0, 0, 0, 0, -1), "url" => $wx->getOauthRedirect(getglobal('siteurl') . 'index.php?mod=system&op=wxredirect&url=' . dzzencode($data['redirecturl']))))));
     if ($ret = $wx->sendMessage($msg)) {
         C::t('notification')->update($data['id'], array('wx_new' => 0));
         return true;
     } else {
         C::t('notification')->update($data['id'], array('wx_new' => $data['wx_new'] + 1));
         $message = 'wx_notification:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg;
         runlog('wxlog', $message);
         return false;
     }
 }
コード例 #2
0
ファイル: wxredirect.php プロジェクト: druphliu/dzzoffice
<?php

/*
 * @copyright   Leyun internet Technology(Shanghai)Co.,Ltd
 * @license     http://www.dzzoffice.com/licenses/license.txt
 * @package     DzzOffice
 * @link        http://www.dzzoffice.com
 * @author      zyx(zyx@dzz.cc)
 */
if (!defined('IN_DZZ')) {
    exit('Access Denied');
}
$code = rawurldecode($_GET['code']);
$redirecturl = dzzdecode(rawurldecode($_GET['url']));
if (empty($redirecturl)) {
    $redirecturl = dzzdecode(rawurldecode($_GET['url']), '', 4);
}
$weObj = new qyWechat(array('token' => getglobal('setting/token_0'), 'appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => 0, 'encodingaeskey' => getglobal('setting/encodingaeskey_0'), 'debug' => true));
$userid = $weObj->getUserId($code, 0);
//生成登录cookie
if ($user = C::t('user')->fetch(str_replace('dzz-', '', $userid))) {
    dsetcookie('auth', authcode("{$user['password']}\t{$user['uid']}", 'ENCODE'), 365 * 24 * 60 * 60, 1, true);
}
@header("Location: {$redirecturl}");
exit;
コード例 #3
0
ファイル: wxreply.php プロジェクト: druphliu/dzzoffice
<?php

/*
 * @copyright   Leyun internet Technology(Shanghai)Co.,Ltd
 * @license     http://www.dzzoffice.com/licenses/license.txt
 * @package     DzzOffice
 * @link        http://www.dzzoffice.com
 * @author      zyx(zyx@dzz.cc)
 */
$weObj = new qyWechat(array('token' => getglobal('setting/token_0'), 'appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => 0, 'encodingaeskey' => getglobal('setting/encodingaeskey_0'), 'debug' => true));
$weObj->valid();
//注意, 企业号与普通公众号不同,必须打开验证,不要注释掉
$type = $weObj->getRev()->getRevType();
switch ($type) {
    case qyWechat::MSGTYPE_TEXT:
        //文本消息
        /*$weObj->text($weObj->getRev()->getRevContent())->reply();*/
        break;
    case qyWechat::MSGTYPE_IMAGE:
        //图片消息
        /*$imageinfo=$weObj->getRev()->getRevPic();
        		$weObj->image($imageinfo['mediaid'])->reply();*/
        break;
    case qyWechat::MSGTYPE_VOICE:
        //语音消息
        /*$imageinfo=$weObj->getRev()->getRevPic();
        		$weObj->image($imageinfo['mediaid'])->reply();*/
        break;
    case qyWechat::MSGTYPE_VIDEO:
        //视频消息
        /*$voice=$weObj->getRev()->getRevVoice();
コード例 #4
0
ファイル: wxsetting.php プロジェクト: druphliu/dzzoffice
     if ($appid) {
         C::t('wx_app')->update($appid, array('menu' => serialize(array('button' => $_GET['menu']))));
     }
     updatecache('setting');
     exit(json_encode(array('msg' => 'success')));
 } elseif ($_GET['action'] == 'menu_publish') {
     //发布到微信
     $data = $setting['menu'] = array('button' => $_GET['menu']);
     C::t('setting')->update('feed_wxsetting', $setting);
     if ($appid) {
         C::t('wx_app')->update($appid, array('menu' => serialize($data)));
     }
     updatecache('setting');
     //发布菜单到微信
     if (getglobal('setting/CorpID') && getglobal('setting/CorpSecret') && $setting['agentid']) {
         $wx = new qyWechat(array('appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret')));
         //处理菜单数据,所有本站链接添加oauth2地址
         foreach ($data['button'] as $key => $value) {
             if ($value['url'] && strpos($value['url'], $_G['siteurl']) === 0) {
                 $data['button'][$key]['url'] = $wx->getOauthRedirect(getglobal('siteurl') . 'index.php?mod=system&op=wxredirect&url=' . dzzencode($value['url']));
             } elseif ($value['sub_button']) {
                 foreach ($value['sub_button'] as $key1 => $value1) {
                     if ($value1['url'] && strpos($value1['url'], $_G['siteurl']) === 0) {
                         $data['button'][$key]['sub_button'][$key1]['url'] = $wx->getOauthRedirect(getglobal('siteurl') . 'index.php?mod=system&op=wxredirect&url=' . dzzencode($value1['url']));
                     }
                 }
             }
         }
         if ($wx->createMenu($data, $setting['agentid'])) {
             exit(json_encode(array('msg' => 'success')));
         } else {
コード例 #5
0
 public function deleteDepartment($id)
 {
     $wx = new qyWechat(array('appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => 0));
     if ($wx->deleteDepartment($id)) {
         return true;
     } else {
         $message = 'deleteDepartment:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg;
         runlog('wxlog', $message);
     }
     return false;
 }
コード例 #6
0
ファイル: index.php プロジェクト: druphliu/dzzoffice
             $ext = array_pop($arr);
             if ($ext && in_array(strtolower($ext), array('jpg', 'jpeg', 'gif', 'png'))) {
                 $settingnew['loginset']['img'] = $back;
                 $settingnew['loginset']['bcolor'] = 'rgb(58, 110, 165)';
             } else {
                 $settingnew['loginset']['url'] = $back;
                 $settingnew['loginset']['bcolor'] = 'rgb(58, 110, 165)';
             }
         }
     } else {
         $settingnew['loginset']['bcolor'] = 'rgb(58, 110, 165)';
     }
 } elseif ($operation == 'qywechat') {
     switch ($_GET['fbind']) {
         case 'bind':
             $wechat = new qyWechat(array('appid' => $settingnew['CorpID'], 'appsecret' => $settingnew['CorpSecret']));
             if (!$wechat->checkAuth()) {
                 showmessage('验证不成功,errCode:' . $wechat->errCode . '; errMsg:' . $wechat->errMsg, dreferer());
             }
             if (empty($setting['token_0'])) {
                 $settingnew['token_0'] = random(8);
             }
             if (empty($setting['encodingaeskey_0'])) {
                 $settingnew['encodingaeskey_0'] = random(43);
             }
             break;
         case 'unbind':
             $settingnew['CorpID'] = '';
             $settingnew['CorpSecret'] = '';
             break;
     }
コード例 #7
0
ファイル: wxreply.php プロジェクト: druphliu/dzzoffice
<?php

/*
 * @copyright   Leyun internet Technology(Shanghai)Co.,Ltd
 * @license     http://www.dzzoffice.com/licenses/license.txt
 * @package     DzzOffice
 * @link        http://www.dzzoffice.com
 * @author      zyx(zyx@dzz.cc)
 */
$setting = unserialize($_G['setting']['feed_wxsetting']);
$weObj = new qyWechat(array('token' => $setting['token'], 'appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => $setting['agentid'], 'encodingaeskey' => $setting['encodingaeskey']));
$weObj->valid();
//注意, 企业号与普通公众号不同,必须打开验证,不要注释掉
$type = $weObj->getRev()->getRevType();
switch ($type) {
    case qyWechat::MSGTYPE_TEXT:
        //文本消息
        // $weObj->text($weObj->getRev()->getRevContent())->reply();
        break;
    case qyWechat::MSGTYPE_IMAGE:
        //图片消息
        /*$imageinfo=$weObj->getRev()->getRevPic();
        		$weObj->image($imageinfo['mediaid'])->reply();*/
        break;
    case qyWechat::MSGTYPE_VOICE:
        //语音消息
        /*$imageinfo=$weObj->getRev()->getRevPic();
        		$weObj->image($imageinfo['mediaid'])->reply();*/
        break;
    case qyWechat::MSGTYPE_VIDEO:
        //视频消息
コード例 #8
0
ファイル: function_core.php プロジェクト: druphliu/dzzoffice
function wx_updateUser($uids)
{
    @set_time_limit(0);
    if (!getglobal('setting/CorpID') || !getglobal('setting/CorpSecret')) {
        return;
    }
    $uids = (array) $uids;
    $wx = new qyWechat(array('appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => 0));
    $ret = 0;
    $syngids = array();
    if ($syngid = getglobal('setting/synorgid')) {
        //设置的需要同步的部门
        $syngids = getOrgidTree($syngid);
    }
    foreach ($uids as $uid) {
        if (!($user = C::t('user')->fetch($uid))) {
            continue;
        }
        $worgids = array();
        if ($orgids = C::t('organization_user')->fetch_orgids_by_uid($uid)) {
            if ($syngids) {
                $orgids = array_intersect($orgids, $syngids);
            }
            if ($orgids) {
                foreach (C::t('organization')->fetch_all($orgids) as $value) {
                    if ($value['worgid']) {
                        $worgids[] = $value['worgid'];
                    } else {
                        if ($worgid = C::t('organization')->wx_update($value['orgid'])) {
                            $worgids[] = $worgid;
                        }
                    }
                }
            }
        }
        if (!$worgids) {
            //用户不在机构和部门中,微信中应该禁用此用户
            $data = array("userid" => "dzz-" . $user['uid'], "enable" => 0, "department" => 1);
            if ($wx->updateUser($data)) {
                $ret += 1;
            } else {
                $message = 'deleteUser:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg;
                runlog('wxlog', $message);
            }
        } else {
            $profile = C::t('user_profile1')->fetch_all($user['uid']);
            if ($wxuser = $wx->getUserInfo('dzz-' . $user['uid'])) {
                //更新用户信息
                $data = array("userid" => "dzz-" . $user['uid'], "name" => $user['username'], "enable" => 1, "email" => $user['email'], "enable" => $user['status'] ? 0 : 1);
                if (array_diff($wxuser['department'], $worgids)) {
                    $data['department'] = $worgids;
                }
                if ($user['phone'] && $user['phone'] != $wxuser['mobile']) {
                    $data['mobile'] = $user['phone'];
                }
                if ($user['weixinid'] && $wxuser['wechat_status'] == 4) {
                    $data['weixinid'] = $user['weixinid'];
                }
                if ($profile['telephone'] && $profile['telephone'] != $wxuser['tel']) {
                    $data['tel'] = $profile['telephone'];
                }
                if ($profile['gender'] && $profile['gender'] - 1 != $wxuser['gender']) {
                    $data['gender'] = $profile['gender'] - 1;
                }
                if ($wx->updateUser($data)) {
                    $ret += 1;
                } else {
                    $message = 'updateUser:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg;
                    runlog('wxlog', $message);
                }
                $setarr = array('wechat_status' => $wxuser['status']);
                $setarr['weixinid'] = empty($wxuser['weixinid']) ? $user['weixinid'] : $wxuser['weixinid'];
                $setarr['phone'] = empty($user['phone']) ? $wxuser['phone'] : $user['phone'];
                $setarr['wechat_userid'] = 'dzz-' . $user['uid'];
                C::t('user')->update($user['uid'], $setarr);
            } else {
                //创建用户信息
                $data = array("userid" => "dzz-" . $user['uid'], "name" => $user['username'], "department" => $worgids, "email" => $user['email'], "weixinid" => $user['wechat'], "enable" => $user['status'] ? 0 : 1);
                if ($user['phone']) {
                    $data['mobile'] = $user['phone'];
                }
                if ($profile['telephone']) {
                    $data['tel'] = $profile['telephone'];
                }
                if ($profile['gender']) {
                    $data['gender'] = $profile['gender'] - 1;
                }
                if ($wx->createUser($data)) {
                    C::t('user')->update($user['uid'], array('wechat_userid' => 'dzz-' . $user['uid']));
                    $ret += 1;
                } else {
                    $message = 'createUser:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg;
                    runlog('wxlog', $message);
                }
            }
        }
    }
    return $ret;
}
コード例 #9
0
ファイル: wxsyn.php プロジェクト: druphliu/dzzoffice
                    }
                }
                exit(json_encode(array('msg' => 'continue', 'start' => $org['orgid'], 'message' => $org['orgname'] . ' <span class="danger">' . $wx->errCode . ':' . $wx->errMsg . '</span>')));
            }
        }
    } else {
        exit(json_encode(array('msg' => 'success')));
    }
} elseif ($do == 'qiwechat_syn_user') {
    $i = intval($_GET['i']);
    $syngids = array();
    if ($syngid = getglobal('setting/synorgid')) {
        //设置的需要同步的部门
        $syngids = getOrgidTree($syngid);
    }
    $wx = new qyWechat(array('appid' => $_G['setting']['CorpID'], 'appsecret' => $_G['setting']['CorpSecret'], 'agentid' => 0));
    if ($user = DB::fetch_first("select u.*,o.orgid from " . DB::table('user') . " u LEFT JOIN " . DB::table('organization_user') . " o ON o.uid=u.uid where u.uid>{$i} and o.orgid>0 order by uid")) {
        $worgids = array();
        if ($orgids = C::t('organization_user')->fetch_orgids_by_uid($user['uid'])) {
            if ($syngids) {
                $orgids = array_intersect($orgids, $syngids);
            }
            if ($orgids) {
                foreach (C::t('organization')->fetch_all($orgids) as $value) {
                    if ($value['worgid']) {
                        $worgids[] = $value['worgid'];
                    } else {
                        if ($worgid = C::t('organization')->wx_update($value['orgid'])) {
                            $worgids[] = $worgid;
                        }
                    }
コード例 #10
0
ファイル: wxreply.php プロジェクト: druphliu/dzzoffice
<?php

/*
 * @copyright   Leyun internet Technology(Shanghai)Co.,Ltd
 * @license     http://www.dzzoffice.com/licenses/license.txt
 * @package     DzzOffice
 * @link        http://www.dzzoffice.com
 * @author      zyx(zyx@dzz.cc)
 */
include_once libfile('function/wx');
if (!$_G['cache']['news:setting']) {
    loadcache('news:setting');
}
$setting = $_G['cache']['news:setting'];
$weObj = new qyWechat(array('token' => $setting['token'], 'appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => $setting['agentid'], 'encodingaeskey' => $setting['encodingaeskey']));
$weObj->valid();
//注意, 企业号与普通公众号不同,必须打开验证,不要注释掉
$type = $weObj->getRev()->getRevType();
switch ($type) {
    case qyWechat::MSGTYPE_TEXT:
        //文本消息
        // $weObj->text($weObj->getRev()->getRevContent())->reply();
        break;
    case qyWechat::MSGTYPE_IMAGE:
        //图片消息
        /*$imageinfo=$weObj->getRev()->getRevPic();
        		$weObj->image($imageinfo['mediaid'])->reply();*/
        break;
    case qyWechat::MSGTYPE_VOICE:
        //语音消息
        /*$imageinfo=$weObj->getRev()->getRevPic();