/** * 同步所有日志 */ public function doUpData(ZOL_Request $input, ZOL_Response $output) { set_time_limit(0); $token = $input->get("token"); //token的验证 // if ($token != md5("c=Rsync_Item&a=UpData" . "AAFDFDF&RE3")) { echo "001"; exit; } $db = Db_AndyouYun::instance(); $data = $input->post("data"); $table = $input->post("table"); if ($data) { $data = base64_decode($data); $data = api_json_decode($data); if ($data) { if (in_array($table, array("staff", "product", "membercate", "productcate", "staffcate", "options", "billsitem"))) { //log_cardchange $okIdArr = array(); foreach ($data as $d) { $site = $d['site']; $objId = $d['objId']; $subSql = "site = '{$site}' and objId = '{$objId}'"; $sql = "select 'x' from {$table} where {$subSql} limit 1 "; $has = $db->getOne($sql); $okIdArr[] = $objId; unset($d['id']); unset($d['rsync']); unset($d['rowTm']); $item = $d; if (!$has) { //如果不存在就插入到本地 Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => "Db_AndyouYun", 'tblName' => $table)); } else { Helper_Dao::updateItem(array('addItem' => $item, 'dbName' => "Db_AndyouYun", 'tblName' => $table, 'where' => $subSql)); } } echo json_encode($okIdArr); } } } exit; }
/** * 检验消息的真实性,并且获取解密后的明文. * <ol> * <li>利用收到的密文生成安全签名,进行签名验证</li> * <li>若验证通过,则提取xml中的加密消息</li> * <li>对消息进行解密</li> * </ol> * * @param $msgSignature string 签名串,对应URL参数的msg_signature * @param $timestamp string 时间戳 对应URL参数的timestamp * @param $nonce string 随机串,对应URL参数的nonce * @param $postData string 密文,对应POST请求的数据 * @param &$msg string 解密后的原文,当return返回0时有效 * * @return int 成功0,失败返回对应的错误码 */ public function DecryptMsg($sMsgSignature, $sTimeStamp = null, $sNonce, $sPostData, &$data) { if (strlen($this->m_sEncodingAesKey) != 43) { return ErrorCode::$IllegalAesKey; } $pc = new Prpcrypt($this->m_sEncodingAesKey); //提取密文 $xmlparse = new XMLParse(); $array = $xmlparse->extract($sPostData); $ret = $array[0]; if ($ret != 0) { return $ret; } if ($sTimeStamp == null) { $sTimeStamp = time(); } $encrypt = $array[1]; $touser_name = $array[2]; //验证安全签名 $sha1 = new SHA1(); $array = $sha1->getSHA1($this->m_sToken, $sTimeStamp, $sNonce, $encrypt); $ret = $array[0]; if ($ret != 0) { return $ret; } $signature = $array[1]; if ($signature != $sMsgSignature) { return ErrorCode::$ValidateSignatureError; } $result = $pc->decrypt($encrypt, $this->m_sCorpid); if ($result[0] != 0) { return $result[0]; } $sMsg = $result[1]; $data = array(); $xml = simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA); $data = api_json_decode(api_json_encode($xml), TRUE); // if($xml){ // foreach ($xml as $key => $value) { // $data[$key] = mb_convert_encoding(strval($value),"GBK","UTF-8");; // } // } return ErrorCode::$OK; }
/** * 更新会员的增量信息 */ public function doUpNew(ZOL_Request $input, ZOL_Response $output) { set_time_limit(600); error_reporting(E_ALL); ini_set("display_errors", 1); $db = Db_Andyou::instance(); $onlyGetFromYun = (int) $input->get("onlyGetFromYun"); //是否仅更新云端数据 $allData = (int) $input->get("allData"); //是否获得所有数据 //------------------------------------ //将本地最新添加或者修改的会员同步到远端 //------------------------------------ //获取一个同步的时间 $sql = "select tm from log_yunrsync where name = 'memberinfo_up'"; $lastUpTm = (int) $db->getOne($sql); if ($lastUpTm > 0) { $lastUpTm = $lastUpTm - 1; } if ($allData) { $lastUpTm = 0; } if (!$onlyGetFromYun) { //是否仅仅获得远端数据 //获得最新添加、修改的会员 $sql = "select id,name,phone,cardno,cateId,byear,bmonth,bday,addTm,remark,introducer,introducerId,allsum,upTm " . " from member where (addTm > {$lastUpTm} or upTm > {$lastUpTm} or rsync = 0) limit 1000"; $res = $db->getAll($sql); $data = array(); if ($res) { foreach ($res as $re) { $re["site"] = $output->sysName; $re["siteObjId"] = $re["id"]; $data[] = $re; } } $jsonstr = base64_encode(api_json_encode($data)); $token = md5("c=Rsync_Member&a=UpNew" . "AAFDFDF&RE3"); $rtnJson = ZOL_Http::curlPost(array('url' => $output->yunUrl . "?c=Rsync_Member&a=UpNew&token={$token}", 'postdata' => "data={$jsonstr}", 'timeout' => 3)); #设置同步状态 $okIdArr = json_decode($rtnJson); if ($okIdArr && is_array($okIdArr)) { foreach ($okIdArr as $id) { echo "{$id} OK<br/>"; $db->query("update member set rsync = 1 where id = {$id} "); } } } //获得云端最新的数据 $urlPart = "c=Rsync_Member&a=GetNew&tm=" . $lastUpTm; $token = md5($urlPart . "AAFDFDF&RE3"); $url = $output->yunUrl . "?{$urlPart}&token={$token}"; $html = ZOL_Http::curlPage(array('url' => $url, 'timeout' => 30)); if ($html) { $data = api_json_decode($html); if ($data) { foreach ($data as $d) { $phone = $d["phone"]; $sql = "select * from member where phone = '{$phone}' limit 1 "; $info = $db->getRow($sql); if (!$info) { //如果不存在就插入到云端 unset($d["id"]); $item = $d; Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => "Db_Andyou", 'tblName' => "member")); } else { #如果云端已经存在了 if ($info["upTm"] < $d["upTm"]) { //云端的更新时间比较老 $item = array('name' => $d["name"], 'cardno' => $d["cardno"], 'cateId' => $d["cateId"], 'byear' => $d["byear"], 'bmonth' => $d["bmonth"], 'bday' => $d["bday"], 'remark' => $d["remark"], 'score' => $d["score"], 'balance' => $d["balance"], 'allsum' => $d["allsum"], 'introducer' => $d["introducer"], 'introducerId' => $d["introducerId"], 'upTm' => $d["upTm"]); Helper_Dao::updateItem(array('editItem' => $item, 'dbName' => "Db_Andyou", 'tblName' => "member", 'where' => "phone = '{$phone}'")); } } } } if (!$onlyGetFromYun) { //是否仅仅获得远端数据 $db->query("delete from log_yunrsync where name = 'memberinfo_up'"); $db->query("insert into log_yunrsync(name,tm) values('memberinfo_up'," . SYSTEM_TIME . ")"); } } echo "OK"; exit; }
/** * 发送模板信息接口 * @param type $paramArr * @return type */ public static function sendTemplateMessage($paramArr) { $options = array('appId' => '', 'appSecret' => '', 'dataArr' => ''); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); if (empty($appId) || empty($appSecret) || empty($dataArr)) { return false; } #获得access_token $tokenDataArr = self::getAccessToken(array('appId' => $appId, 'appSecret' => $appSecret)); #获得 access_token $accessToken = ""; if (!empty($tokenDataArr['state'])) { $accessToken = $tokenDataArr['data']; } else { return false; } $jsonStr = ""; $jsonStr = API_Http::curlPost(array('url' => 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $accessToken, 'postdata' => !empty($dataArr) ? api_json_encode($dataArr) : '')); $jsonArr = array(); $jsonArr = api_json_decode($jsonStr); if (!empty($jsonArr['errmsg'])) { if ($jsonArr['errmsg'] == 'ok' && $jsonArr['errcode'] == '0') { return true; } } else { return false; } }
/** * 同步最新数据 */ public function doUpNew(ZOL_Request $input, ZOL_Response $output) { $token = $input->get("token"); //token的验证 // if ($token != md5("c=Rsync_Member&a=UpNew" . "AAFDFDF&RE3")) { echo "001"; exit; } $db = Db_AndyouYun::instance(); //获得本地的会员 $data = $input->post("data"); if ($data) { $data = base64_decode($data); $data = api_json_decode($data); if ($data) { $okIdArr = array(); foreach ($data as $d) { $phone = $d["phone"]; $sql = "select * from member where phone = '{$phone}' limit 1 "; $info = $db->getRow($sql); if (!$info) { //如果不存在就插入到云端 $okIdArr[] = $d["id"]; unset($d["id"]); unset($d["rsync"]); $item = $d; $item["upTm"] = SYSTEM_TIME; Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => "Db_AndyouYun", 'tblName' => "member")); } else { #如果云端已经存在了 if ($info["upTm"] < $d["upTm"]) { //云端的更新时间比较老 $item = array('name' => $d["name"], 'cardno' => $d["cardno"], 'cateId' => $d["cateId"], 'byear' => $d["byear"], 'bmonth' => $d["bmonth"], 'bday' => $d["bday"], 'remark' => $d["remark"], 'introducer' => $d["introducer"], 'introducerId' => $d["introducerId"], 'upTm' => $d["upTm"]); Helper_Dao::updateItem(array('editItem' => $item, 'dbName' => "Db_AndyouYun", 'tblName' => "member", 'where' => "phone = '{$phone}'")); } } } echo json_encode($okIdArr); } } exit; }
/** * 接受队列过来的数据进行处理-生成订单 * /?c=Index&a=DealQueueOrder */ public function doDealQueueOrder(ZOL_Request $input, ZOL_Response $output) { $data = @file_get_contents('php://input'); if (!$data) { # 未接收到数据 Helper_Reward_LogModel::insertLog(array('order_number' => '', 'msg' => "[8010]处理订单队列异常", 'content' => 'error[处理订单队列-post接收到的数据:];data:' . $data)); Helper_Reward_RewardFunc::ajaxExit(array('resultCode' => 8010, 'resultDesc' => 'error[处理订单队列-post接收到的数据:];data:' . $data, 'retry' => false, 'forQueue' => 1, 'toLog' => 1)); } $jsonReturnArr = array(); #$data = mb_convert_encoding($data, 'utf-8', 'gb2312'); #$dataObj = json_decode($data); $dataObj = api_json_decode($data); /* $cacheKey = 'CMS_Reward_Queue_Test:insertData'; ZOL_Api::run("Kv.MongoCenter.set" , array( 'module' => 'cms', #业务名 'tbl' => 'zol_index', #表名 'key' => $cacheKey, #key 'data' => $dataObj, #数据 'life' => 1*3600, #生命期,3天 )); */ # 查询文章的作者 $dataObj['payee'] = Helper_Reward_RewardFunc::getArticleAuthor(array('articleId' => $dataObj['article_id'])); if (!$dataObj) { $jsonReturnArr['resultCode'] = 801; $jsonReturnArr['resultDesc'] = "[801]error-接收过来的额xml进行api_json_decode处理后异常.data:{$data}"; $jsonReturnArr['retry'] = false; } else { $id = Helper_Reward_RewardModel::insertData(array('order_name' => $dataObj['order_name'], 'order_number' => $dataObj['order_number'], 'article_id' => $dataObj['article_id'], 'ext1' => $dataObj['ext1'], 'ext2' => $dataObj['ext2'], 'url' => $dataObj['url'], 'insert_date' => $dataObj['insert_date'], 'pay_time' => NULL, 'custmer' => $dataObj['custmer'], 'money' => $dataObj['money'], 'message' => $dataObj['message'], 'payment' => $dataObj['payment'], 'order_status' => $dataObj['order_status'], 'payee' => $dataObj['payee'], 'service_type' => $dataObj['service_type'])); } if ($id) { $jsonReturnArr['resultCode'] = 800; $jsonReturnArr['resultDesc'] = 'success'; $jsonReturnArr['retry'] = false; } Helper_Reward_RewardFunc::ajaxExit(array('resultCode' => $jsonReturnArr['resultCode'], 'resultDesc' => $jsonReturnArr['resultDesc'], 'retry' => $jsonReturnArr['retry'], 'forQueue' => 1, 'toLog' => 1)); /* $id = Helper_Reward_RewardModel::insertData(array( 'order_name' => $dataObj->order_name, 'order_number' => $dataObj->order_number, 'article_id' => $dataObj->article_id, 'url' => $dataObj->url, 'insert_date' => $dataObj->insert_date, 'pay_time' => NULL, 'custmer' => $dataObj->custmer, 'money' => $dataObj->money, 'message' => $dataObj->message, 'payment' => $dataObj->payment, 'order_status' => $dataObj->order_status, 'payee' => $dataObj->payee,# 'service_type' => $dataObj->service_type,# 1资讯文章打赏 2.论坛(暂不支持) #'debug' => 1, ));*/ return ''; }
/** * 获取数据 */ private static function fetchData($paramArr) { $options = array('apiName' => '', 'data' => false, 'format' => 'json'); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); //系统级参数部分 $reqData = array('app_key' => self::$_APPKEY, 'app_secret' => self::$_APPSECRET, 'api_name' => $apiName, 'format' => $format); if ($data) { $reqData = array_merge($data, $reqData); } $url = self::$_APPCALLBURL . "?" . http_build_query($reqData); # $responseData = API_Http::curlPage(array('url' => $url, 'timeout' => 30)); if ($responseData && $responseData != "null") { return api_json_decode($responseData); } else { return false; } }
/** * 获取数据 */ private static function fetchData($paramArr) { $options = array('apiName' => '', 'data' => false, 'format' => 'json'); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); //系统级参数部分 $sysParam = array('app_key' => self::$_APPKEY, 'method' => $apiName, 'timestamp' => date("Y-m-d H:i:s"), 'v' => "2.0"); //具体一个api的参数的处理 $apiParam = array(); ksort($data); $apiParam['360buy_param_json'] = json_encode($data); //参数的签名部分 $sysParam["sign"] = self::generateSign(array_merge($sysParam, $apiParam)); $url = self::buildUrl($sysParam); //拼装URL //去请求数据 $responseData = self::doCurl(array('url' => $url, 'apiParams' => $apiParam, 'timeout' => 30)); if ($responseData) { #解码过程中遇到了一些特殊字符,对这些字符进行处理 $responseData = str_replace(' ', '', $responseData); return api_json_decode($responseData); } else { return false; } }
public static function getReport($paramArr) { $options = array('startTime' => '', 'endTime' => '', 'hour' => '', 'num' => 0, 'offset' => 0, 'orderField' => '', 'orderBy' => 0); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); $whereArr = array(); //if($dimension){#按照维度选择 // $whereArr[] = '"Dimension":['.$dimension.']'; //} //if($metric){#按照指标选择 // $whereArr[] = '"Metric":['.$metric.']'; //} $dateStyle = 7; #小时 if ($startTime && $endTime) { #时间范围选择 if ('' !== $hour) { $dateStyle = 19; #分钟 $hour = (int) $hour; if (10 > $hour) { $hour = '0' . $hour; } //$next_hour = date('H', strtotime('+1 hours', strtotime($startTime.' '.$hour.':00:00'))); $startTime = $startTime . ' ' . $hour . ':00:00'; $endTime = $endTime . ' ' . $hour . ':59:59'; } $whereArr[] = '"DateRange":{"End":"' . $endTime . '","Start":"' . $startTime . '"}'; } if ($num || $offset) { #分页范围 $whereArr[] = '"Paging":{"RowsNumber":' . $num . ',"StartIndex":' . $offset . '}'; } if ($orderField) { #排序 $whereArr[] = '"Orderings":{"Field":"' . $orderField . '","SortOrder":"' . ($orderBy == 1 ? 'DESC' : 'ASC') . '"}'; } $data = false; if ($whereArr) { $postData = '{"Dimension":[5,' . $dateStyle . '],"Metric":[2,3],' . implode(',', $whereArr) . '}'; $data = self::postData(array('url' => "ReportService.svc/Get", 'postdata' => $postData)); } if ($data) { $data = api_json_decode($data, true); $outArr = array(); if ($data) { $dataValueArr = $data['Rows']; if ($dataValueArr) { foreach ($dataValueArr as $row) { $mediabuyId = $row[0]; $dateArr = explode(' ', $row[1]); $hour = $dateArr[1]; $outArr[$mediabuyId][$hour] = array('clickPv' => $row[2], 'impPv' => $row[3], 'clickUv' => 0, 'impUv' => 0); } } } return $outArr; } }
/** * 获取实时天气信息 */ public static function getForecast3d($paramArr) { $options = array('url' => '', 'dataType' => 0); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); if (!$url) { return null; } $json = self::getCurlData(array('url' => $url, 'retry' => 3)); if ($dataType == 0) { return $json; } #转换为数组 $data = api_json_decode($json, true); if (!$data || empty($data['f'])) { return null; } $outArr = array('cityInfo' => array(), 'forecast' => array()); #城市信息 if (!empty($data['c'])) { $cityInfo = $data['c']; $tempArr = array(); $tempArr['areaid'] = isset($cityInfo['c1']) ? $cityInfo['c1'] : ''; $tempArr['cityEn'] = isset($cityInfo['c2']) ? $cityInfo['c2'] : ''; $tempArr['cityCn'] = isset($cityInfo['c3']) ? $cityInfo['c3'] : ''; $tempArr['districtEn'] = isset($cityInfo['c4']) ? $cityInfo['c4'] : ''; $tempArr['districtCn'] = isset($cityInfo['c5']) ? $cityInfo['c5'] : ''; $tempArr['provinceEn'] = isset($cityInfo['c6']) ? $cityInfo['c6'] : ''; $tempArr['provinceCn'] = isset($cityInfo['c7']) ? $cityInfo['c7'] : ''; $tempArr['countryEn'] = isset($cityInfo['c8']) ? $cityInfo['c8'] : ''; $tempArr['countryCn'] = isset($cityInfo['c9']) ? $cityInfo['c9'] : ''; $tempArr['cityLevel'] = isset($cityInfo['c10']) ? $cityInfo['c10'] : ''; $tempArr['areaCode'] = isset($cityInfo['c11']) ? $cityInfo['c11'] : ''; $tempArr['postCode'] = isset($cityInfo['c12']) ? $cityInfo['c12'] : ''; $tempArr['longitude'] = isset($cityInfo['c13']) ? $cityInfo['c13'] : ''; $tempArr['latitude'] = isset($cityInfo['c14']) ? $cityInfo['c14'] : ''; $tempArr['altitude'] = isset($cityInfo['c15']) ? $cityInfo['c15'] : ''; $tempArr['radar'] = isset($cityInfo['c16']) ? $cityInfo['c16'] : ''; $outArr['cityInfo'] = $tempArr; } #预报信息 $foreArr = array(); $forecast = $data['f']; $tempArr['pubDate'] = isset($data['f0']) ? $data['f0'] : ''; if (!empty($forecast['f1'])) { foreach ($forecast['f1'] as $val) { $row = array(); $row['dayNo'] = isset($val['fa']) ? strval($val['fa']) : ''; $row['dayWeather'] = ''; if (array_key_exists($row['dayNo'], self::$weatchConf)) { $row['dayWeather'] = self::$weatchConf[$row['dayNo']]['cn']; } $row['eveNo'] = isset($val['fb']) ? strval($val['fb']) : ''; $row['eveWeather'] = ''; if (array_key_exists($row['eveNo'], self::$weatchConf)) { $row['eveWeather'] = self::$weatchConf[$row['eveNo']]['cn']; } #天气类型 $row['dayTemperature'] = isset($val['fc']) ? $val['fc'] : ''; $row['eveTemperature'] = isset($val['fd']) ? $val['fd'] : ''; #早晚风向 $row['dayDirection'] = isset($val['fe']) ? strval($val['fe']) : ''; $row['dayDirectionName'] = ''; if (array_key_exists($row['dayDirection'], self::$windDirection)) { $row['dayDirectionName'] = self::$windDirection[$row['dayDirection']]['cn']; } $row['eveDirection'] = isset($val['ff']) ? strval($val['ff']) : ''; $row['eveDirectionName'] = ''; if (array_key_exists($row['eveDirection'], self::$windDirection)) { $row['eveDirectionName'] = self::$windDirection[$row['eveDirection']]['cn']; } #风力 $row['dayScale'] = isset($val['fg']) ? $val['fg'] : ''; $row['dayScaleName'] = ''; if (array_key_exists($row['dayScale'], self::$windForce)) { $row['dayScaleName'] = self::$windForce[$row['dayScale']]['cn']; } $row['eveScale'] = isset($val['fh']) ? $val['fh'] : ''; $row['eveScaleName'] = ''; if (array_key_exists($row['eveScale'], self::$windForce)) { $row['eveScaleName'] = self::$windForce[$row['eveScale']]['cn']; } #日出日落 $row['sunrise'] = isset($val['fi']) ? $val['fi'] : ''; $foreArr[] = $row; } } $outArr['forecast'] = $foreArr; return $outArr; }