信呼OA版本v2.3.8
This commit is contained in:
62
webmain/model/wxgzh/indexModel.php
Normal file
62
webmain/model/wxgzh/indexModel.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
class wxgzh_indexClassModel extends wxgzhModel
|
||||
{
|
||||
public function initWxgzh()
|
||||
{
|
||||
$this->settable('wotpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统上模版消息
|
||||
*/
|
||||
public function getxinhutpl()
|
||||
{
|
||||
$barr[] = array(
|
||||
'title' => '流程待办',
|
||||
'params'=> array(
|
||||
'name' => '姓名',
|
||||
'applyname' => '申请人',
|
||||
'deptname' => '申请人部门',
|
||||
'sericnum' => '单号',
|
||||
'modename' => '模块名称',
|
||||
'summary' => '备注摘要'
|
||||
),
|
||||
'paramsdefault'=> array(
|
||||
'name' => '赵子龙',
|
||||
'applyname' => '张飞',
|
||||
'deptname' => '技术部',
|
||||
'sericnum' => 'TEST-20190326',
|
||||
'modename' => '请假条',
|
||||
'summary' => '请假时间2019-03-26的9时到18共8小时'
|
||||
),
|
||||
);
|
||||
$xhtype = getconfig('xinhutype');
|
||||
if(!isempt($xhtype)){
|
||||
$obj = m($xhtype);
|
||||
if(method_exists($obj, 'getwxgzhtpl')){
|
||||
$narr = $obj->getwxgzhtpl();
|
||||
if(is_array($narr))foreach($narr as $k=>$rs1)$barr[]=$rs1;
|
||||
}
|
||||
}
|
||||
return $barr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发模版消息
|
||||
*/
|
||||
private $tplidarr = array();
|
||||
public function sendtpl($openid, $tplid, $params=array(),$istest=false)
|
||||
{
|
||||
return $this->setbackarr('不能使用');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取我消息模版列表
|
||||
*/
|
||||
public function gettpllist()
|
||||
{
|
||||
return $this->setbackarr('不能使用');
|
||||
}
|
||||
}
|
||||
116
webmain/model/wxgzh/oauthModel.php
Normal file
116
webmain/model/wxgzh/oauthModel.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
class wxgzh_oauthClassModel extends wxgzhModel
|
||||
{
|
||||
|
||||
public function initWxgzh()
|
||||
{
|
||||
$this->settable('wouser');
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整到获取
|
||||
*/
|
||||
public function oauthto($dlx='we')
|
||||
{
|
||||
$this->readwxset();
|
||||
if($this->appid==''){
|
||||
$this->returnerrmsg($dlx, '没有配置公众号');
|
||||
return false;
|
||||
}
|
||||
$state = $this->rock->get('state','bang');
|
||||
$redurl = ''.getconfig('outurl',URL).'?d='.$dlx.'&a=oauthback&m=login&state='.$state.'';
|
||||
$redirect_uri = urlencode($redurl);
|
||||
$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$this->appid.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_userinfo&state='.$state.'#wechat_redirect';
|
||||
$this->rock->location($url);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function returnerrmsg($dlx='we',$errmsg, $ocan='')
|
||||
{
|
||||
$url = '?d='.$dlx.'&m=login&errmsg='.$this->rock->jm->base64encode($errmsg).''.$ocan.'';
|
||||
$this->rock->location($url);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到openid获取用户信息
|
||||
*/
|
||||
public function oauthback()
|
||||
{
|
||||
$code = $this->rock->get('code');
|
||||
$state = $this->rock->get('state');
|
||||
if($code=='')return '无法取得微信授权';
|
||||
|
||||
$this->readwxset();
|
||||
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appid.'&secret='.$this->secret.'&code='.$code.'&grant_type=authorization_code';
|
||||
$result = c('curl')->getcurl($url);
|
||||
$openid = '';
|
||||
$access_token = '';
|
||||
$errmsg = '无法获取微信用户openid';
|
||||
if($result != ''){
|
||||
$arr = json_decode($result);
|
||||
if(isset($arr->openid))$openid = $arr->openid;
|
||||
if(isset($arr->access_token))$access_token = $arr->access_token;
|
||||
if(isset($arr->errmsg))$errmsg = $arr->errmsg;
|
||||
}
|
||||
|
||||
if($openid != ''){
|
||||
$this->rock->savecookie('wxopenid', $openid);
|
||||
$nuarr = $this->getone("`openid`='$openid'");
|
||||
$uoid = 0;
|
||||
//不要去重复拉起微信用户信息了
|
||||
if($nuarr){
|
||||
$uoid = (int)$nuarr['id'];
|
||||
$this->update(array(
|
||||
'optdt' => $this->rock->now,
|
||||
'uid' => $this->adminid
|
||||
), $uoid); //更新最后时间
|
||||
return $nuarr;
|
||||
}
|
||||
$gurl = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';
|
||||
$result = c('curl')->getcurl($gurl);//拉取用户信息
|
||||
if($result != ''){
|
||||
$arr = json_decode($result, true);
|
||||
if(isset($arr['errcode']) && $arr['errcode']!=0){
|
||||
$errmsg = $arr['errmsg'];
|
||||
}else{
|
||||
$where = 'id='.$uoid.'';
|
||||
$uarr['openid'] = $arr['openid'];
|
||||
$uarr['nickname'] = $arr['nickname'];
|
||||
$uarr['sex'] = $arr['sex'];
|
||||
$uarr['province'] = $arr['province'];
|
||||
$uarr['city'] = $arr['city'];
|
||||
$uarr['country'] = $arr['country'];
|
||||
$uarr['headimgurl'] = $arr['headimgurl'];
|
||||
$uarr['optdt'] = $this->rock->now;
|
||||
$uarr['ip'] = $this->rock->ip;
|
||||
$uarr['uid'] = $this->adminid;
|
||||
if($uoid==0){
|
||||
$uarr['adddt'] = $this->rock->now;
|
||||
$where = '';
|
||||
}
|
||||
$bo = $this->record($uarr, $where);
|
||||
$errmsg = '';//为空说明对了
|
||||
if(!$bo)$errmsg = $this->db->error();
|
||||
}
|
||||
}else{
|
||||
$errmsg = '无法获取微信用户信息';
|
||||
}
|
||||
}
|
||||
if($errmsg==''){
|
||||
return $uarr;
|
||||
}else{
|
||||
return $errmsg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取当前绑定微信用户信息
|
||||
*/
|
||||
public function getbdwx($uid)
|
||||
{
|
||||
$rs = $this->getone('`uid`='.$uid.'','`openid`,`nickname`,`headimgurl`');
|
||||
if(!$rs)$rs['nickname'] = '';
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
32
webmain/model/wxgzh/signjssdkModel.php
Normal file
32
webmain/model/wxgzh/signjssdkModel.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
class wxgzh_signjssdkClassModel extends wxgzhModel
|
||||
{
|
||||
private function createNonceStr($length = 16) {
|
||||
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
$str = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getsignsdk($url) {
|
||||
$this->readwxset();
|
||||
$jsapiTicket = $this->getticket();
|
||||
$timestamp = time();
|
||||
$nonceStr = $this->createNonceStr();
|
||||
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
|
||||
$signature = sha1($string);
|
||||
$signPackage = array(
|
||||
"appId" => $this->appid,
|
||||
"nonceStr" => $nonceStr,
|
||||
"timestamp" => $timestamp,
|
||||
|
||||
"url" => $url,
|
||||
"signature" => $signature,
|
||||
"jsapiTicket" => $jsapiTicket,
|
||||
"rawString" => $string
|
||||
);
|
||||
return $signPackage;
|
||||
}
|
||||
}
|
||||
145
webmain/model/wxgzh/wxgzh.php
Normal file
145
webmain/model/wxgzh/wxgzh.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
class wxgzhModel extends Model
|
||||
{
|
||||
//定义远程连接的
|
||||
protected $URL_public = 'https://api.weixin.qq.com/cgi-bin/';
|
||||
|
||||
protected $URL_gettoken = 'token';
|
||||
protected $URL_jsapiticket = 'ticket/getticket';
|
||||
|
||||
//获取用户信息跟openid
|
||||
protected $URL_userinfo = 'user/info';
|
||||
|
||||
//发模版消息的
|
||||
protected $URL_tplsend = 'message/template/send';
|
||||
protected $URL_tplgetlist = 'template/get_all_private_template';
|
||||
|
||||
|
||||
|
||||
public $appid = '';
|
||||
public $optionpid = '-4';
|
||||
public $backarr = array();
|
||||
protected $secret = '';
|
||||
public function initWxgzh(){}
|
||||
|
||||
public function initModel()
|
||||
{
|
||||
$this->backarr = array('errcode'=>-1, 'msg'=>'sorry,error');
|
||||
$this->option = m('option');
|
||||
$this->readwxset();
|
||||
$this->initWxgzh();
|
||||
}
|
||||
|
||||
public function gettourl($can)
|
||||
{
|
||||
$url = $this->URL_public;
|
||||
if(substr($url,0,4)!='http'){
|
||||
$url=$this->rock->jm->uncrypt($url);
|
||||
$url.=$this->rock->jm->uncrypt($this->$can);
|
||||
}else{
|
||||
$url.=$this->$can;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
//读取配置
|
||||
public function readwxset()
|
||||
{
|
||||
if($this->appid!='')return $this->appid;
|
||||
$this->appid = $this->option->getval('wxgzh_appid');
|
||||
$this->secret = $this->option->getval('wxgzh_secret');
|
||||
$this->corpid = $this->option->getval('weixinqy_corpid');
|
||||
return $this->appid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可以使用公众号定位的
|
||||
* $lx 0有企业号判断
|
||||
*/
|
||||
public function isusegzh($lx=0)
|
||||
{
|
||||
if(!$this->rock->iswebbro(0) || $this->rock->isqywx)return 0;
|
||||
$this->readwxset();
|
||||
$is = 1;
|
||||
if($this->appid=='' || $this->secret=='')$is = 0;
|
||||
if($lx==0 && !isempt($this->corpid))$is = 0;
|
||||
return $is;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有设置微信公众号
|
||||
*/
|
||||
public function issetwxgzh()
|
||||
{
|
||||
$str = $this->option->getval('wxgzh_token');
|
||||
if($str){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//获取token
|
||||
public function gettoken()
|
||||
{
|
||||
$time = date('Y-m-d H:i:s', time()-2*3600);
|
||||
$num = 'wxgzh_token';
|
||||
$rs = $this->option->getone("`num`='$num' and `optdt`>'$time'");
|
||||
$val = '';
|
||||
if($rs)$val = $rs['value'];
|
||||
if(isempt($val)){
|
||||
$this->readwxset();
|
||||
$secret = $this->secret;
|
||||
if($this->appid=='' || $this->secret=='')showreturn('','没有设置公众号',201);
|
||||
if(isempt($secret))return '';
|
||||
$url = ''.$this->gettourl('URL_gettoken').'?grant_type=client_credential&appid='.$this->appid.'&secret='.$secret.'';
|
||||
$result = c('curl')->getcurl($url);
|
||||
if($result != ''){
|
||||
$arr = json_decode($result);
|
||||
if(!isset($arr->access_token)){
|
||||
showreturn('',$result,201);
|
||||
}else{
|
||||
$val = $arr->access_token;
|
||||
$this->option->setval($num.'@'.$this->optionpid.'', $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function getticket()
|
||||
{
|
||||
$time = date('Y-m-d H:i:s', time()-2*3600);
|
||||
$num = 'wxgzh_ticket';
|
||||
$rs = $this->option->getone("`num`='$num' and `optdt`>'$time'");
|
||||
$val = '';
|
||||
if($rs)$val = $rs['value'];
|
||||
if(isempt($val)){
|
||||
$token = $this->gettoken();
|
||||
$url = ''.$this->gettourl('URL_jsapiticket').'?access_token='.$token.'&type=jsapi';
|
||||
$result = c('curl')->getcurl($url);
|
||||
if($result != ''){
|
||||
$arr = json_decode($result);
|
||||
if(!isset($arr->ticket)){
|
||||
showreturn('', $result, 201);
|
||||
}else{
|
||||
$val = $arr->ticket;
|
||||
$this->option->setval($num.'@'.$this->optionpid.'', $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
||||
public function setbackarr($msg, $code=-1)
|
||||
{
|
||||
$this->backarr = array('errcode'=>$code, 'msg'=>$msg);
|
||||
return $this->backarr;
|
||||
}
|
||||
|
||||
public function clearalltoken()
|
||||
{
|
||||
$this->option->update("value=null", "`num` like 'wxgzh\_%'");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user