Commit 8a203e50 by biao

111

parent fd00aed0
......@@ -210,7 +210,7 @@ CREATE TABLE IF NOT EXISTS user_login_dat(
id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
openid varchar(64) NOT NULL,
seesion_key text NOT NULL,
session_key text NOT NULL,
delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;
......
......@@ -9,21 +9,21 @@
class UserLoginDat extends CompassDynamicData
{
var $openid;
var $seesion_key;
var $session_key;
var $delete_flg;
/**
* 构造实现。user_mst创建实例。
* 构造实现。user_login_dat创建实例。
*
* @access public
* @param mixed user_mst
* @param mixed user_login_dat
*/
function constructor($record)
{
parent::constructor($record);
$this->openid = $record["openid"];
$this->seesion_key = $record["seesion_key"];
$this->session_key = $record["session_key"];
$this->delete_flg = $record["delete_flg"];
}
......@@ -42,7 +42,7 @@ class UserLoginDat extends CompassDynamicData
$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
$w_param["delete_flg"] = "false";
}
$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"];
}
......@@ -74,7 +74,7 @@ class UserLoginDat extends CompassDynamicData
$param = array();
$param["delete_flg"] = false;
return CompassDBHandler::getById("UserLoginDat", "user_mst", $id, $param);
return CompassDBHandler::getById("UserLoginDat", "user_login_dat", $id, $param);
}
// -- 这里开始Dynamic ---
......@@ -89,10 +89,10 @@ class UserLoginDat extends CompassDynamicData
$v_param = array();
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");
// 保存
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");
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/UserBuyMemberDat.inc");
require_once(COMPASS_LIB_ROOT . "/cn/compass/entity/UserLoginDat.inc");
// definition
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");
//生成二维码类
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,64 +14,58 @@ ErrorLogger::doOutput("Compass...ajax_check_user_registed.php....openId=" . $ope
$result = array();
//如果都为空说明调用错误
if(empty($jsCode) && empty($openId)) {
if(empty($jsCode)) {
$result["message"] = "参数错误!";
responseNG($result);
}
//有code的情况下
if(!empty($jsCode)) {
$appId = WECHAT_APP_ID;
$appSecret = WECHAT_APP_SECRET;
//调用微信接口获取用户的openId和unionId
//调用服务器查询并插入数据
$ch = curl_init();
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appId . "&secret=" . $appSecret . "&js_code=" . $jsCode . "&grant_type=authorization_code";
//通过code换取网页授权access_token
$weixin = file_get_contents($url);
$json = json_decode($weixin); //对JSON格式的字符串进行编码
$wxArray = get_object_vars($json);//转换成数组
$openId = $wxArray["openid"];
$appId = WECHAT_APP_ID;
$appSecret = WECHAT_APP_SECRET;
//调用微信接口获取用户的openId和unionId
//调用服务器查询并插入数据
$ch = curl_init();
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appId . "&secret=" . $appSecret . "&js_code=" . $jsCode . "&grant_type=authorization_code";
//通过code换取网页授权access_token
$weixin = file_get_contents($url);
$json = json_decode($weixin); //对JSON格式的字符串进行编码
$wxArray = get_object_vars($json);//转换成数组
$openId = $wxArray["openid"];
$sessionKey = $wxArray["session_key"];
$unionId = "";
if(isset($wxArray["unionid"])) {
$unionId = $wxArray["unionid"];
if(!empty($openId)) {
//检索数据库
$param['openid'] = $openId;
$param['delete_flg'] = false;
$tmpUserMst = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMst)) {
$result["registed"] = false;
$result["openId"] = $openId;
$result["unionId"] = $unionId;
$result["message"] = "未注册!";
responseOK($result);
} else {
$result["registed"] = true;
$result["openId"] = $openId;
$result["unionId"] = $unionId;
$result["message"] = "已注册!";
responseNG($result);
}
} else {
$result["message"] = "参数错误!";
responseNG($result);
}
} else if(!empty($openId)) {
//有openId的情况下
}
if(!empty($openId)) {
//保存session_key
$userLoginDat = new UserLoginDat();
$userLoginDat->openid = $openId;
$userLoginDat->session_key = $sessionKey;
$userLoginDat->save();
//检索数据库
$param['openid'] = $openId;
$param['delete_flg'] = false;
$tmpUserMst = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMst)) {
$tmpUserMstList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMstList)) {
$result["registed"] = false;
$result["openId"] = $openId;
$result["unionId"] = $unionId;
$result["message"] = "未注册!";
responseOK($result);
} else {
$result["registed"] = true;
$result["openId"] = $openId;
$result["unionId"] = $tmpUserMstList[0]->unionid;
$result["message"] = "已注册!";
responseNG($result);
}
} else {
$result["message"] = "参数错误!";
responseNG($result);
}
function responseNG($result) {
$result = array("status"=>"NG", "result"=>$result);
print json_encode($result);
......
......@@ -3,85 +3,50 @@
// 【区域管理】获取指定学校的志愿者活动列表
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");
$originalSource = ParamUtil::getRequestNumber("originalSource", 0);
$openId = ParamUtil::getRequestString("openid");
$iv = ParamUtil::getRequestString("iv");
$encryptedData = ParamUtil::getRequestString("encryptedData");
//参数检查
if(empty($schoolNo) || empty($originalSource)) {
if(empty($openId) || empty($iv) || empty($encryptedData)) {
$result["message"] = "参数错误!";
responseNG($result);
}
$result = array();
//查询学校是否存在
//todo 以后改为 从家校或者家园系统查询
//获取session_key解析数据
$param = array();
$param['school_no'] = $schoolNo;
$param['original_source'] = $originalSource;
$param['openid'] = $openId;
$param['delete_flg'] = false;
$schoolList = SchoolMst::getList($param,'id','desc', 0, 1);
if(empty($schoolList)) {
$result["message"] = "参数错误!";
$tmpList = UserLoginDat::getList($param,'id','desc', 0, 1);
if(empty($tmpList)) {
$result["message"] = "数据错误!";
responseNG($result);
}
$schoolMst = $schoolList[0];
//查询该学校的志愿者人数
$memberCount = 0;
$sql = "select count(*) as member_count from user_mst where delete_flg = false and school_no='{$schoolNo}' and original_source='{$originalSource}'";
$db = &CompassDBManager::getInstance();
$tmpList = $db->executeQuery($sql);
if(!empty($tmpList)) {
$memberCount = $tmpList[0]['member_count'];
}
//查询该校能力分汇总
$abilityPoint = 0;
$sql = "select sum(ability_point) as ability_point from user_mst where delete_flg = false and school_no='{$schoolNo}' and original_source='{$originalSource}'";
$db = &CompassDBManager::getInstance();
$tmpList = $db->executeQuery($sql);
if(!empty($tmpList)) {
$abilityPoint = $tmpList[0]['ability_point'];
}
//查询该学校的志愿者活动列表
$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;
$sessionKey = $tmpList[0]->session_key;
$pc = new WXBizDataCrypt(WECHAT_APP_ID, $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $userInfo );
//解析userInfo获取unionId
$json = json_decode($userInfo); //对JSON格式的字符串进行编码
$wxArray = get_object_vars($json);//转换成数组
$unionId = $wxArray["unionId"];
ErrorLogger::doOutput("Compass...ajax_get_unionid.php....End.", 0);
if ($errCode == 0) {
//删除该用户的所有session_key
$sql = "delete from user_login_dat where openid='{$openId}'";
$db = &CompassDBManager::getInstance();
$db->executeQuery($sql);
$result["unionId"] = $unionId;
responseOK($result);
} else {
$result["message"] = "解析错误!";
responseNG($result);
}
//接口返回数据
$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) {
$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