public function sendMessage($type, $custom_data, $receiveUserId, $transmissionContent, $title, $text) { $url = Common_Config::SSO_TRANS_URL; $accessKeyId = Common_Config::UDO_OP_DOMAINID; $sendUserId = 0; $receiveUserIds = ""; foreach ($receiveUserId as $k => $val) { if (array_key_exists($k + 1, $receiveUserId)) { $receiveUserIds .= $val . ","; } else { $receiveUserIds .= $val; } } //print_r($receiveUserIds); $post_data = array("type" => $type, "customData" => $custom_data, "accessKeyId" => $accessKeyId, "sendUserId" => $sendUserId, "receiveUserId" => $receiveUserIds, "transmissionContent" => $transmissionContent, "title" => $title, "text" => $text); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); //print_r($array); //print_r($post_data); //判断是否返回失败信息 if (is_array($array) && array_key_exists('code', $array) && $array['code'] == 0) { return -1; } return $array; }
function getAvailableRes($uid, $domainId) { $schoolModel = new SchoolModel(); $tblResource = new DB_Sso_Resource(); $tblBought = new DB_Udo_UserBought(); $availableArray = []; //首先从SSO获取到云滴请求的资源列表 $url = Common_Config::SSO_USER_SINGLE_RESOURCE; $post_data = array("domainId" => $domainId, "userId" => $uid, "parentId" => 0, "localType" => Common_Config::UDO_LOCAL_COURSE_TYPE); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); //获取频道的定价信息 $schoolPrice = $schoolModel->getSchoolPrice($domainId, $uid); $totalPrice = 0; $hasBought = 0; $children = []; foreach ($array as $k => $course) { //对于每一个父节点,根据id判断定价类型,现价和原价 $priceInfo = $tblResource->scalar("price_type,cur_price,ori_price", "where id = {$course['id']}"); //接下来获取当前资源用户是否已经购买 $bought = $tblBought->scalar("id", "where userId = {$uid} and schoolId = {$domainId} and resourceId = {$course['id']} and resourceType = 2"); if ($bought || $priceInfo['price_type'] == 3) { if ($bought) { $hasBought = 1; } continue; } else { array_push($children, array("courseId" => $course['id'], "priceType" => $priceInfo['price_type'], "price" => $priceInfo['cur_price'], "localId" => $this->getLocalId($course['id'], $domainId)['local_id'])); $totalPrice += $priceInfo['cur_price']; } } if (!$children) { return -1; } //生成返回列表 //如果用户购买过频道的课程,那么不再按折扣价格计算 if ($hasBought) { $price = $totalPrice; } else { $price = $schoolPrice['price']; } $availableArray = array("schoolId" => $domainId, "priceType" => $schoolPrice['priceType'], "price" => $price); return array_merge($availableArray, array("children" => $children)); }
function searchSchool($keyword, $ssotoken) { $tblLog = new DB_Udo_SearchLog(); $userModel = new UserModel(); $uid = $userModel->getUserId($ssotoken); //print_r($keyword); //先进行结果查询,将查询出来的id记录下来 $tblEntrance = new DB_Sso_Entrance(); //记录结果id的数组 $result = []; $resultIds = []; //关键字搜索的长度限制 //获取输入的关键字的字符串长度 /* $length = strlen($keyword); for($i = $length;$i >=1 ;$i--){ //对关键词进行拆分 $split_array = str_split($keyword,$i); foreach ($split_array as $k=>$value){ //对于每一个截断后的结果进行搜索 $name = $tblEntrance->fetchAll("id","where customer_name like '%{$value}%' or customer_title like '%{$value}%' "); $result = array_merge($result,$name); } } $resultIds = $tblEntrance->columnRow($result,"id"); print_r(array_unique($resultIds)); print_r(str_split("外语")); print_r(preg_split("/[\s,]+/","外语 教学,研究")); $tempaddtext="php对UTF8字体串进行单字分割返回数组"; //$cind代表的是字符位移 $cind = 0; $arr_cont = array(); for ($i = 0; $i < strlen($tempaddtext); $i++) { if (strlen(substr($tempaddtext, $cind, 1)) > 0) { if (ord(substr($tempaddtext, $cind, 1)) < 192) { if (substr($tempaddtext, $cind, 1) != " ") { array_push($arr_cont, substr($tempaddtext, $cind, 1));} $cind++;} elseif(ord(substr($tempaddtext, $cind, 1)) < 224) { array_push($arr_cont, substr($tempaddtext, $cind, 2)); $cind+=2;} else {array_push($arr_cont, substr($tempaddtext, $cind, 3));$cind+=3;}}} print_r($arr_cont);*/ $result = $tblEntrance->fetchAll("id", "where customer_name like '%{$keyword}%' or customer_title like '%{$keyword}%' "); $resultIds = $tblEntrance->columnRow($result, 'id'); if (!$resultIds) { $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => -1, "createTime" => time())); return -1; } //print_r($resultIds); $result_array = []; //从sso获取所有频道 $url = Common_Config::SSO_SCHOOL_URL; $post_data = array("ssotoken" => $ssotoken); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); $array['entrances'] = $this->schoolOrder($array); //针对搜索结果,返回频道的基础信息 foreach ($resultIds as $l) { foreach ($array['entrances'] as $k => $val) { if ($val['id'] == $l) { $price = $this->getSchoolPrice($l, $uid); $val = array_merge($val, array("isSubscribed" => $this->getIfSub($val['id'], $uid) ? 1 : 0), $price); $index = 0; //过滤掉apiBaseUrl项目 while ($key = key($val)) { if ($key == "apiBaseUrl") { array_splice($val, $index, 1); break; } $index++; next($val); } array_push($result_array, $val); } } if (count($result_array) == count($resultIds)) { break; } } if (!$result_array) { $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => -1, "createTime" => time())); return -1; } $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => count($result_array), "resultString" => implode(',', $resultIds), "createTime" => time())); //print_r($result_array); return $result_array; }
function getUserAuth($userId, $schoolId, $ssotoken = "") { $url = Common_Config::SSO_SCHOOL_URL; $post_data = array("ssotoken" => $ssotoken); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); $isAuthorized = 0; foreach ($array['entrances'] as $k => $val) { if ($val['id'] == $schoolId) { //print_r($val['id']); $isAuthorized = $val['isAuthorized']; break; } } return $isAuthorized; }
function getCredit($userId, $actionId, $schoolId) { $tblCredit = new DB_Udo_CreditAction(); $tblAccount = new DB_Pay_Account(); $tblCreditLog = new DB_Udo_UserCreditLog(); $rand = new Common_Char(); //获取该动作的基础信息 $result = $tblCredit->scalar("creditAmount,name,outputInput,ratio,times,isSynthesized,actionType", "where actionId = {$actionId} and isValid = 1"); if (!$result) { return Common_Error::ERROR_ACTION; } $upTimes = $result['times']; //接下来获取用户当日的同action的操作 $today = strtotime("today"); $tomorrow = strtotime("tomorrow"); $statusSuccess = Common_Config::CREDIT_SUCCESS; $sameTimes = $tblCreditLog->queryCount("where actionId = {$actionId} and userId = {$userId} and createTime between {$today} and {$tomorrow}\r\n and status = {$statusSuccess}"); //如果今日增长已经超出限额 if ($sameTimes >= $upTimes) { return Common_Error::ERROR_OVER_TIMES; } //否则更新账户信息,如果失败再重试三次 $retry = 0; $updateAccount = 0; $id = $tblAccount->scalar("id,amt,score", "where sso_id = {$userId}"); //print_r($id); //$testUpdate = $tblAccount->query("update account set score = 1895 where id = {$id['id']}"); //print_r($testUpdate); while (!$updateAccount && $retry <= 3) { $score = $id['score'] + $result['creditAmount']; //print_r($score); //$updateAccount = $tblAccount->query("update account set score = {$score} where id = {$id['id']}"); $remark = "日常活动"; $random = $rand->getRandChar(8); $sign = md5(Common_Config::PAY_OSID . $userId . $result['creditAmount'] . $remark . $random . Common_Config::PAY_SECRET); //print_r(Common_Config::PAY_OSID.(string)$userId.(string)$score.$remark.$random.Common_Config::PAY_SECRET); $url = Common_Config::CREDIT_UPDATE; $post_data = array("osid" => Common_Config::PAY_OSID, "ssoId" => $userId, "score" => $result['creditAmount'], "remark" => $remark, "random" => $random, "sign" => $sign); $cl = new Common_Curl(); $updateAccount = $cl->request($url, $post_data); $retry++; //print_r($updateAccount); } //账户更新失败返回失败信息 if (!$updateAccount) { return Common_Error::ERROR_UPDATE_BALANCE; } //账户更新成功,插入学分和U币变动日支 $tblCreditLog->insert(array("userId" => $userId, "creditSource" => Common_Config::DAILY_CREDIT_ACTION, "actionId" => $actionId, "info" => $result['name'] . "获得学分", "amt" => $result['creditAmount'], "status" => Common_Config::CREDIT_SUCCESS, "schoolId" => $schoolId, "createTime" => time())); return Common_Error::ERROR_SUCCESS; }
function testSearchAction() { $url = "http://182.92.118.115:8080/school/searchSchool/"; $post_data = array("ssotoken" => "token88bb31f0-5e54-43b0-af4e-20efa6df23f7LiH0zZaP", "keyword" => "外"); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); print_r($array); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $array); }
/** * 用户是否存在 */ public function getAdAction() { //广告接口首先拿客户端传来的ssotoken 在SSO进行验证获取用户信息 $request = $this->getRequest(); $userModel = new UserModel(); $userModel->logout(); if ('POST' == $request->getMethod()) { $token = trim($this->post()->get("ssotoken")); } else { $token = $this->get("ssotoken"); } //$token = "1"; if (!$token) { $this->displayJsonUdo(Common_Error::ERROR_PARAM); } //获取到用户信息 $url = Common_Config::SSO_SCHOOL_URL; $post_data = array("ssotoken" => $token); //print_r($post_data); $cl = new Common_Curl(); $result = $cl->request($url, $post_data); /* $result = array("id"=>8 , "grade"=>11,"province"=>3,"city"=>4,"area"=>5, "entrances"=>array(0=>array("id"=>1,"name"=>"双十","title"=>"双十网校","grade"=>11,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>4), 1=>array("id"=>2,"name"=>"华英","title"=>"华英网校","grade"=>14,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>6), 2=>array("id"=>3,"name"=>"三明","title"=>"三明网校","grade"=>15,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>4)));*/ //print_r($result); if (array_key_exists('code', $result) && $result['code'] == 0) { $this->displayJsonUdo(Common_Error::ERROR_FAIL, null, "SSO没有返回正确的用户信息哦~"); } //$result = array ("id"=> 2779,"province"=>3,"grade"=>11); //$result = array ("id"=> 2779,"province"=> 0,"grade"=>11); //sso返回成功,开始进行广告过滤 //print_r($result); //过滤出和用户所在地区和年级一致的广告 $ad = new AdModel(); $adlist = $ad->getAd($result); $uid = $userModel->getUserId($token); /*$kaixin = $ad->filterPrimary($uid); if(is_array($kaixin)) $adlist = $kaixin;*/ //计算总竞价值 $price_sum = 0; $temp_arr = array(); foreach ($adlist as $i => $val) { $price_sum += $val['price']; } //生成随机数 $arr = array(); $arr[] = rand(1, 100); $arr = array_unique($arr); $rand = implode(" ", $arr); //获得随机url $url = []; $rate = 0; foreach ($adlist as $i => $val) { $temp_arr[$i] = $val['price'] / $price_sum * 100 + ($i - 1 >= 0 ? $temp_arr[$i - 1] : 0); //print_r($i." ".$temp_arr[$i]); if ($rand <= $temp_arr[$i] && $rand >= ($i - 1 >= 0 ? $temp_arr[$i - 1] : 0)) { $url = $val; $rate = $val['price'] / $price_sum; } } //将推送的广告写入广告推送表 $ad->adLog($url['id'], 0, $rate); $ad->adPushSum($url['id']); $ad->adStatistics($url['id']); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $url); }
function testNotifyAction() { $url = "http://182.92.118.115:8080/Account/getPayResult/"; $osid = 1; $transNo = "123"; $status = 1; $random = "123"; $notifyTime = '2015-10-1'; $sign = md5($osid . $transNo . $status . $random . $notifyTime . Common_Config::PAY_SECRET); $post_data = array("osid" => $osid, "transNo" => $transNo, "status" => $status, "random" => $random, "notifyTime" => $notifyTime, "sign" => $sign); $cl = new Common_Curl(); $array = $cl->request($url, $post_data); print_r($array); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $array); }
function getOrderResult($uid, $transNo) { $tblTrans = new DB_Udo_TransNotify(); $isSolid = Common_Config::NOTIFY_SOLID; //计算超时时间 //其实计算点 $startMicroTime = time(); do { $result = $tblTrans->scalar("statusValue", "where transNo = {$transNo} and isSolid = {$isSolid}"); //终止计算点 $endMicroTime = time(); //时间间隔 $interval = $endMicroTime - $startMicroTime; } while (!$result && $interval < 3); //如果timeout结束还没有接到通知,去公共云主动查询,如果查询没有结果返回失败状态 if (!$result) { $rand = new Common_Char(); $random = $rand->getRandChar(8); $sign = md5(Common_Config::PAY_OSID . $transNo . $random . Common_Config::PAY_SECRET); $post_data = array("osid" => Common_Config::PAY_OSID, "transNo" => $transNo, "random" => $random, "sign" => $sign); $url = Common_Config::TRANS_QUERY; $cl = new Common_Curl(); $result = $cl->request($url, $post_data); if (!$result) { return Common_Error::ERROR_TRANS_UNKNOWN; } } //$result['status'] = 0; //如果查到了交易的信息,判断交易的状态 $notifyUncertain = Common_Config::NOTIFY_UNCERTAIN; $updateId = $tblTrans->scalar("id", "where transNo = '{$transNo}' and isSolid = {$notifyUncertain}"); //print_r($result); switch ($result['statusValue']) { case Common_Config::ORDER_SUCCESS: //如果获取到了支付成功的通知信息,更新U币交易日志和order的状态 //先从order表获取交易的coinId $tblOrder = new DB_Udo_Order(); $tblCoinInfo = new DB_Udo_CoinInfo(); $coin = $tblOrder->scalar("id,coinId", "where transNo = '{$transNo}'"); $coinId = $coin['coinId']; $coinInfo = $tblCoinInfo->scalar("amt,price", "where id = {$coinId}"); $info = "充值" . $coinInfo['amt'] . "U币"; //将U币充值信息写入coinLog $this->insertTransLog($uid, $coinInfo['amt'], $info, Common_Config::COIN_LOG); //$tblOrder->update($coin['id'],array("status"=>Common_Config::ORDER_SUCCESS)); $statusSuccess = Common_Config::ORDER_SUCCESS; $tblOrder->query("update udo_order set status = {$statusSuccess} where id = {$coin['id']}"); //更新通知的状态为可靠 if ($updateId) { $notifySolid = Common_Config::NOTIFY_SOLID; $tblTrans->query("update udo_trans_notify set isSolid = {$notifySolid} where id = {$updateId['id']}"); //$tblTrans->update($updateId['id'],array("isSolid"=>Common_Config::NOTIFY_SOLID)); } return Common_Error::ERROR_ORDER_SUCCESS; //如果订单是未支付的状态,那么将订单信息写入transNotify //如果订单是未支付的状态,那么将订单信息写入transNotify case Common_Config::ORDER_NOT_PAY: //如果没有写入,则写入信息 if (!$updateId) { $tblTrans->insert(array("transNo" => $transNo, "isSolid" => Common_Config::NOTIFY_UNCERTAIN, "createTime" => time())); } return Common_Error::ERROR_TRANS_UNKNOWN; //如果接收到订单失败的消息, //如果接收到订单失败的消息, case Common_Config::ORDER_FAIL: if ($updateId) { $notifySolid = Common_Config::NOTIFY_SOLID; $tblTrans->query("update udo_trans_notify set isSolid = {$notifySolid} where id = {$updateId['id']}"); //$tblTrans->update($updateId['id'],array("isSolid"=>Common_Config::NOTIFY_SOLID)); } return Common_Error::ERROR_TRANS_FAIL; case Common_Config::ORDER_CLOSED: if ($updateId) { $notifySolid = Common_Config::NOTIFY_SOLID; $tblTrans->query("update udo_trans_notify set isSolid = {$notifySolid} where id = {$updateId['id']}"); //$tblTrans->update($updateId['id'],array("isSolid"=>Common_Config::NOTIFY_SOLID)); } return Common_Error::ERROR_TRANS_CLOSED; default: return Common_Error::ERROR_TRANS_UNKNOWN; } }