Commit 50fef6ba by shijiuyan

Merge remote-tracking branch 'origin/master'

parents 46cce7e6 392c7d13
...@@ -210,7 +210,7 @@ CREATE TABLE IF NOT EXISTS user_login_dat( ...@@ -210,7 +210,7 @@ CREATE TABLE IF NOT EXISTS user_login_dat(
id bigint unsigned NOT NULL PRIMARY KEY auto_increment, id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
openid varchar(64) NOT NULL, openid varchar(64) NOT NULL,
seesion_key text NOT NULL, session_key text NOT NULL,
delete_flg tinyint(1) NOT NULL DEFAULT '0' delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4; ) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;
......
...@@ -9,21 +9,21 @@ ...@@ -9,21 +9,21 @@
class UserLoginDat extends CompassDynamicData class UserLoginDat extends CompassDynamicData
{ {
var $openid; var $openid;
var $seesion_key; var $session_key;
var $delete_flg; var $delete_flg;
/** /**
* 构造实现。user_mst创建实例。 * 构造实现。user_login_dat创建实例。
* *
* @access public * @access public
* @param mixed user_mst * @param mixed user_login_dat
*/ */
function constructor($record) function constructor($record)
{ {
parent::constructor($record); parent::constructor($record);
$this->openid = $record["openid"]; $this->openid = $record["openid"];
$this->seesion_key = $record["seesion_key"]; $this->session_key = $record["session_key"];
$this->delete_flg = $record["delete_flg"]; $this->delete_flg = $record["delete_flg"];
} }
...@@ -42,7 +42,7 @@ class UserLoginDat extends CompassDynamicData ...@@ -42,7 +42,7 @@ class UserLoginDat extends CompassDynamicData
$w_param["delete_flg"] = "false"; $w_param["delete_flg"] = "false";
} }
return CompassDBHandler::getList("UserLoginDat", "user_mst", $w_param, $orderkey, $direction, $offset, $limit); return CompassDBHandler::getList("UserLoginDat", "user_login_dat", $w_param, $orderkey, $direction, $offset, $limit);
} }
/** /**
...@@ -60,7 +60,7 @@ class UserLoginDat extends CompassDynamicData ...@@ -60,7 +60,7 @@ class UserLoginDat extends CompassDynamicData
$w_param["delete_flg"] = "false"; $w_param["delete_flg"] = "false";
} }
$db = CompassDBManager::getInstance(); $db = CompassDBManager::getInstance();
$result = $db->doSelect("user_mst", $w_param, null, null, null, null, "count(*) as count"); $result = $db->doSelect("user_login_dat", $w_param, null, null, null, null, "count(*) as count");
return $result[0]["count"]; return $result[0]["count"];
} }
...@@ -74,7 +74,7 @@ class UserLoginDat extends CompassDynamicData ...@@ -74,7 +74,7 @@ class UserLoginDat extends CompassDynamicData
$param = array(); $param = array();
$param["delete_flg"] = false; $param["delete_flg"] = false;
return CompassDBHandler::getById("UserLoginDat", "user_mst", $id, $param); return CompassDBHandler::getById("UserLoginDat", "user_login_dat", $id, $param);
} }
// -- 这里开始Dynamic --- // -- 这里开始Dynamic ---
...@@ -89,10 +89,10 @@ class UserLoginDat extends CompassDynamicData ...@@ -89,10 +89,10 @@ class UserLoginDat extends CompassDynamicData
$v_param = array(); $v_param = array();
ParamUtil::copyObj2Array($v_param, $this, "openid"); ParamUtil::copyObj2Array($v_param, $this, "openid");
ParamUtil::copyObj2Array($v_param, $this, "seesion_key"); ParamUtil::copyObj2Array($v_param, $this, "session_key");
ParamUtil::copyObj2Array($v_param, $this, "delete_flg"); ParamUtil::copyObj2Array($v_param, $this, "delete_flg");
// 保存 // 保存
parent::_save("user_mst", $v_param); parent::_save("user_login_dat", $v_param);
} }
} }
\ No newline at end of file
<?php
/**
* error code 说明.
* <ul>
* <li>-41001: encodingAesKey 非法</li>
* <li>-41003: aes 解密失败</li>
* <li>-41004: 解密后得到的buffer非法</li>
* <li>-41005: base64加密失败</li>
* <li>-41016: base64解密失败</li>
* </ul>
*/
class ErrorCode
{
public static $OK = 0;
public static $IllegalAesKey = -41001;
public static $IllegalIv = -41002;
public static $IllegalBuffer = -41003;
public static $DecodeBase64Error = -41004;
}
?>
\ No newline at end of file
<?php
/**
* 对微信小程序用户加密数据的解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/
include_once "errorCode.php";
class WXBizDataCrypt
{
private $appid;
private $sessionKey;
/**
* 构造函数
* @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 ErrorCode::$IllegalAesKey;
}
$aesKey=base64_decode($this->sessionKey);
if (strlen($iv) != 24) {
return ErrorCode::$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 ErrorCode::$IllegalBuffer;
}
if( $dataObj->watermark->appid != $this->appid )
{
return ErrorCode::$IllegalBuffer;
}
$data = $result;
return ErrorCode::$OK;
}
}
...@@ -49,6 +49,7 @@ require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/FamilyEventMemberDat.inc"); ...@@ -49,6 +49,7 @@ require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/FamilyEventMemberDat.inc");
require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/DonationsEventDat.inc"); require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/DonationsEventDat.inc");
require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/UserDonationDat.inc"); require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/UserDonationDat.inc");
require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/UserBuyMemberDat.inc"); require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/UserBuyMemberDat.inc");
require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/UserLoginDat.inc");
// definition // definition
require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/definition/ImageType.inc"); require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/definition/ImageType.inc");
......
...@@ -18,5 +18,9 @@ require_once(EXTRA_LIB_ROOT . "/cn/extralib/wxpay/WxPay.php"); ...@@ -18,5 +18,9 @@ require_once(EXTRA_LIB_ROOT . "/cn/extralib/wxpay/WxPay.php");
//生成二维码类 //生成二维码类
require_once(EXTRA_LIB_ROOT . "/cn/extralib/phpqrcode.php"); require_once(EXTRA_LIB_ROOT . "/cn/extralib/phpqrcode.php");
//解码相关类
require_once(EXTRA_LIB_ROOT . "/cn/extralib/wxDataCrypt/wxBizDataCrypt.php");
require_once(EXTRA_LIB_ROOT . "/cn/extralib/wxDataCrypt/errorCode.php");
?> ?>
...@@ -14,31 +14,40 @@ ErrorLogger::doOutput("Compass...ajax_check_user_registed.php....openId=" . $ope ...@@ -14,31 +14,40 @@ ErrorLogger::doOutput("Compass...ajax_check_user_registed.php....openId=" . $ope
$result = array(); $result = array();
//如果都为空说明调用错误 //如果都为空说明调用错误
if(empty($jsCode) && empty($openId)) { if(empty($jsCode)) {
$result["message"] = "参数错误!"; $result["message"] = "参数错误!";
responseNG($result); responseNG($result);
} }
//有code的情况下 //有code的情况下
if(!empty($jsCode)) { $appId = WECHAT_APP_ID;
$appId = WECHAT_APP_ID; $appSecret = WECHAT_APP_SECRET;
$appSecret = WECHAT_APP_SECRET; //调用微信接口获取用户的openId和unionId
//调用微信接口获取用户的openId和unionId //调用服务器查询并插入数据
//调用服务器查询并插入数据 $ch = curl_init();
$ch = curl_init(); $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appId . "&secret=" . $appSecret . "&js_code=" . $jsCode . "&grant_type=authorization_code";
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appId . "&secret=" . $appSecret . "&js_code=" . $jsCode . "&grant_type=authorization_code"; //通过code换取网页授权access_token
//通过code换取网页授权access_token $weixin = file_get_contents($url);
$weixin = file_get_contents($url); $json = json_decode($weixin); //对JSON格式的字符串进行编码
$json = json_decode($weixin); //对JSON格式的字符串进行编码 $wxArray = get_object_vars($json);//转换成数组
$wxArray = get_object_vars($json);//转换成数组 $openId = $wxArray["openid"];
$openId = $wxArray["openid"]; $sessionKey = $wxArray["session_key"];
$unionId = "";
if(isset($wxArray["unionid"])) {
$unionId = $wxArray["unionid"]; $unionId = $wxArray["unionid"];
if(!empty($openId)) { }
if(!empty($openId)) {
//保存session_key
$userLoginDat = new UserLoginDat();
$userLoginDat->openid = $openId;
$userLoginDat->session_key = $sessionKey;
$userLoginDat->save();
//检索数据库 //检索数据库
$param['openid'] = $openId; $param['openid'] = $openId;
$param['delete_flg'] = false; $param['delete_flg'] = false;
$tmpUserMst = UserMst::getList($param,'id','desc', 0, 1); $tmpUserMstList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMst)) { if(empty($tmpUserMstList)) {
$result["registed"] = false; $result["registed"] = false;
$result["openId"] = $openId; $result["openId"] = $openId;
$result["unionId"] = $unionId; $result["unionId"] = $unionId;
...@@ -47,31 +56,16 @@ if(!empty($jsCode)) { ...@@ -47,31 +56,16 @@ if(!empty($jsCode)) {
} else { } else {
$result["registed"] = true; $result["registed"] = true;
$result["openId"] = $openId; $result["openId"] = $openId;
$result["unionId"] = $unionId; $result["unionId"] = $tmpUserMstList[0]->unionid;
$result["message"] = "已注册!"; $result["message"] = "已注册!";
responseNG($result); responseNG($result);
} }
} else { } else {
$result["message"] = "参数错误!"; $result["message"] = "参数错误!";
responseNG($result); responseNG($result);
}
} else if(!empty($openId)) {
//有openId的情况下
//检索数据库
$param['openid'] = $openId;
$param['delete_flg'] = false;
$tmpUserMst = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMst)) {
$result["registed"] = false;
$result["message"] = "未注册!";
responseOK($result);
} else {
$result["registed"] = true;
$result["message"] = "已注册!";
responseNG($result);
}
} }
function responseNG($result) { function responseNG($result) {
$result = array("status"=>"NG", "result"=>$result); $result = array("status"=>"NG", "result"=>$result);
print json_encode($result); print json_encode($result);
......
...@@ -3,85 +3,50 @@ ...@@ -3,85 +3,50 @@
// 【区域管理】获取指定学校的志愿者活动列表 // 【区域管理】获取指定学校的志愿者活动列表
require_once ("../user_include.inc"); require_once ("../user_include.inc");
ErrorLogger::doOutput("Compass...ajax_get_school_detail.php....Start.", 0); ErrorLogger::doOutput("Compass...ajax_get_unionid.php....Start.", 0);
//获取参数 //获取参数
$schoolNo = ParamUtil::getRequestString("schoolNo"); $openId = ParamUtil::getRequestString("openid");
$originalSource = ParamUtil::getRequestNumber("originalSource", 0); $iv = ParamUtil::getRequestString("iv");
$encryptedData = ParamUtil::getRequestString("encryptedData");
//参数检查 //参数检查
if(empty($schoolNo) || empty($originalSource)) { if(empty($openId) || empty($iv) || empty($encryptedData)) {
$result["message"] = "参数错误!"; $result["message"] = "参数错误!";
responseNG($result); responseNG($result);
} }
$result = array(); //获取session_key解析数据
//查询学校是否存在
//todo 以后改为 从家校或者家园系统查询
$param = array(); $param = array();
$param['school_no'] = $schoolNo; $param['openid'] = $openId;
$param['original_source'] = $originalSource;
$param['delete_flg'] = false; $param['delete_flg'] = false;
$schoolList = SchoolMst::getList($param,'id','desc', 0, 1); $tmpList = UserLoginDat::getList($param,'id','desc', 0, 1);
if(empty($schoolList)) { if(empty($tmpList)) {
$result["message"] = "参数错误!"; $result["message"] = "数据错误!";
responseNG($result); responseNG($result);
} }
$sessionKey = $tmpList[0]->session_key;
$schoolMst = $schoolList[0];
$pc = new WXBizDataCrypt(WECHAT_APP_ID, $sessionKey);
//查询该学校的志愿者人数 $errCode = $pc->decryptData($encryptedData, $iv, $userInfo );
$memberCount = 0; //解析userInfo获取unionId
$sql = "select count(*) as member_count from user_mst where delete_flg = false and school_no='{$schoolNo}' and original_source='{$originalSource}'"; $json = json_decode($userInfo); //对JSON格式的字符串进行编码
$db = &CompassDBManager::getInstance(); $wxArray = get_object_vars($json);//转换成数组
$tmpList = $db->executeQuery($sql); $unionId = $wxArray["unionId"];
if(!empty($tmpList)) {
$memberCount = $tmpList[0]['member_count']; ErrorLogger::doOutput("Compass...ajax_get_unionid.php....End.", 0);
} if ($errCode == 0) {
//删除该用户的所有session_key
//查询该校能力分汇总 $sql = "delete from user_login_dat where openid='{$openId}'";
$abilityPoint = 0; $db = &CompassDBManager::getInstance();
$sql = "select sum(ability_point) as ability_point from user_mst where delete_flg = false and school_no='{$schoolNo}' and original_source='{$originalSource}'"; $db->executeQuery($sql);
$db = &CompassDBManager::getInstance(); $result["unionId"] = $unionId;
$tmpList = $db->executeQuery($sql); responseOK($result);
if(!empty($tmpList)) { } else {
$abilityPoint = $tmpList[0]['ability_point']; $result["message"] = "解析错误!";
} responseNG($result);
//查询该学校的志愿者活动列表
$volunteerEventList = array();
$param = array();
$param['school_no'] = $schoolNo;
$param['original_source'] = $originalSource;
$param['status_NOT'] = "NEW";
$param['status_NOT'] = "NG";
$param['delete_flg'] = false;
$tmpVolunteerEventList = VolunteerEventDat::getList($param,'id','desc');
//加工返回的数据
//设置状态和招募范围
foreach($tmpVolunteerEventList as $tmp) {
$tmp->status_title = "征集中";
$tmp->scope = "校内";
if($tmp->include_social_user) {
$tmp->scope = "校内.社会人士";
}
$volunteerEventList[] = $tmp;
} }
//接口返回数据
$result["schoolTitle"] = $schoolMst->title;
$result["memberCount"] = $memberCount;
$result["abilityPoint"] = $abilityPoint;
$result["volunteerEventList"] = $volunteerEventList;
ErrorLogger::doOutput("Compass...ajax_get_school_detail.php....End.", 0);
//返回结果
responseOK($result);
function responseNG($result) { function responseNG($result) {
$result = array("status"=>"NG", "result"=>$result); $result = array("status"=>"NG", "result"=>$result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment