apiKey = config('constants.UmengApiKey'); $this->apiSecurity = config('constants.UmengApiSecurity'); } private function UmengRequest(){ $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http $reqPolicy->useHttps = false; //$reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; return $reqPolicy; } public function getDayNews($data){ try { $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com'); $syncAPIClient = new SyncAPIClient ($clientPolicy); $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http // $reqPolicy->useHttps = false; $reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; $param = new UmengUappGetNewAccountsParam(); $param->setAppkey($data['appKey']); $param->setStartDate($data['startDate']); $param->setEndDate($data['endDate']); $param->setPeriodType($data['type']); $param->setChannel($data['channel']); $request = new APIRequest (); $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.getNewAccounts", 1); $request->apiId = $apiId; $request->requestEntity = $param; $result = new UmengUappGetNewAccountsResult(); $syncAPIClient->send($request, $result, $reqPolicy); $result = self::object_array($result); sort($result); return $result[2]['newAccountInfo'][0]['newUser']; }catch (OceanException $ex){ echo "Exception occured with code["; echo $ex->getErrorCode (); echo "] message ["; echo $ex->getMessage (); echo "]."; } } public function getChannelData($data){ try { // ---------------------------example start--------------------------------- // 请替换第一个参数apiKey和第二个参数apiSecurity $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com'); $syncAPIClient = new SyncAPIClient ( $clientPolicy ); $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http // $reqPolicy->useHttps = false; $reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; // --------------------------构造参数---------------------------------- $param = new UmengUappGetChannelDataParam(); $param->setAppkey($data['appKey']); $param->setDate($data['lastData']); $param->setPerPage('100'); $param->setPage('1'); // --------------------------构造请求---------------------------------- $request = new APIRequest (); $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.getChannelData", 1 ); $request->apiId = $apiId; $request->requestEntity = $param; // --------------------------构造结果---------------------------------- $result = new UmengUappGetChannelDataResult(); $syncAPIClient->send ( $request, $result, $reqPolicy ); $syncAPIClient->send($request, $result, $reqPolicy); $result = self::object_array($result); sort($result); return $result[3]; // ----------------------------example end------------------------------------- } catch ( OceanException $ex ) { echo "Exception occured with code["; echo $ex->getErrorCode (); echo "] message ["; echo $ex->getMessage (); echo "]."; } } /** * 获取友盟数据 * @param $data * @throws Exception */ public function getUmengResponse($data){ try { include_once ('Umeng/com/umeng/uapp/param/UmengUappEventGetUniqueUsersParam.class.php'); include_once ('Umeng/com/umeng/uapp/param/UmengUappEventGetUniqueUsersResult.class.php'); // ---------------------------example start--------------------------------- // 请替换第一个参数apiKey和第二个参数apiSecurity $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com'); $syncAPIClient = new SyncAPIClient ( $clientPolicy ); $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http // $reqPolicy->useHttps = false; $reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; // --------------------------构造参数---------------------------------- $param = new UmengUappEventGetUniqueUsersParam(); $param->setAppkey($data['appKey']); $param->setStartDate($data['startDate']); $param->setEndDate($data['endDate']); $param->setEventName($data['event']); // --------------------------构造请求---------------------------------- $request = new APIRequest (); $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.event.getUniqueUsers", 1 ); $request->apiId = $apiId; $request->requestEntity = $param; // --------------------------构造结果---------------------------------- $result = new UmengUappEventGetUniqueUsersResult(); $syncAPIClient->send ( $request, $result, $reqPolicy ); $result = self::object_array($result); sort($result); return $result[2]['uniqueUsers']; // ----------------------------example end------------------------------------- } catch ( OceanException $ex ) { return false; echo "Exception occured with code["; echo $ex->getErrorCode (); echo "] message ["; echo $ex->getMessage (); echo "]."; } } public static function object_array($array) { if(is_object($array)) { $array = (array)$array; } if(is_array($array)) { foreach($array as $key=>$value) { $array[$key] = self::object_array($value); } } return $array; } public function getAppList($data){ try{ include_once ('Umeng/com/umeng/uapp/param/UmengUappGetAppListParam.class.php'); include_once ('Umeng/com/umeng/uapp/param/UmengUappGetAppListResult.class.php'); $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com'); $syncAPIClient = new SyncAPIClient ( $clientPolicy ); $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http // $reqPolicy->useHttps = false; $reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; // --------------------------构造参数---------------------------------- $param = new UmengUappGetAppListParam(); $param->setPage($data['page']); $param->setPerPage($data['perPage']); // --------------------------构造请求---------------------------------- $request = new APIRequest (); $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.getAppList", 1 ); $request->apiId = $apiId; $request->requestEntity = $param; // --------------------------构造结果---------------------------------- $result = new UmengUappGetAppListResult(); $syncAPIClient->send ( $request, $result, $reqPolicy ); $result = self::object_array($result); sort($result); return $result[3]['appInfos']; // ----------------------------example end------------------------------------- } catch ( OceanException $ex ) { return false; echo "Exception occured with code["; echo $ex->getErrorCode (); echo "] message ["; echo $ex->getMessage (); echo "]."; } } public function getTypeApp($data){ try { // ---------------------------example start--------------------------------- include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetDataParam.class.php'); include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetDataResult.class.php'); // 请替换第一个参数apiKey和第二个参数apiSecurity $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com'); $syncAPIClient = new SyncAPIClient ( $clientPolicy ); $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http // $reqPolicy->useHttps = false; $reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; // --------------------------构造参数---------------------------------- $param = new UmengUappEventParamGetDataParam(); $param->setAppkey($data['appKey']); $param->setStartDate($data['startDate']); $param->setEndDate($data['endDate']); $param->setEventName($data['eventName']); $param->setEventParamName($data['eventName']); $param->setParamValueName($data['type']); // --------------------------构造请求---------------------------------- $request = new APIRequest (); $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.event.param.getData", 1 ); $request->apiId = $apiId; $request->requestEntity = $param; // --------------------------构造结果---------------------------------- $result = new UmengUappEventParamGetDataResult(); $syncAPIClient->send ( $request, $result, $reqPolicy ); $result = self::object_array($result); sort($result); return $result[2]['paramValueData']; // ----------------------------example end------------------------------------- } catch ( OceanException $ex ) { return false; echo "Exception occured with code["; echo $ex->getErrorCode (); echo "] message ["; echo $ex->getMessage (); echo "]."; } } public function getValueList($data){ try { // ---------------------------example start--------------------------------- include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetValueListParam.class.php'); include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetValueListResult.class.php'); // 请替换第一个参数apiKey和第二个参数apiSecurity $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com'); $syncAPIClient = new SyncAPIClient ( $clientPolicy ); $reqPolicy = new RequestPolicy (); $reqPolicy->httpMethod = "POST"; $reqPolicy->needAuthorization = false; $reqPolicy->requestSendTimestamp = false; // 测试环境只支持http // $reqPolicy->useHttps = false; $reqPolicy->useHttps = true; $reqPolicy->useSignture = true; $reqPolicy->accessPrivateApi = false; // --------------------------构造参数---------------------------------- $param = new UmengUappEventParamGetValueListParam(); $param->setAppkey($data['appKey']); $param->setStartDate($data['startDate']); $param->setEndDate($data['endDate']); $param->setEventName($data['eventName']); $param->setEventParamName($data['eventName']); // --------------------------构造请求---------------------------------- $request = new APIRequest (); $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.event.param.getValueList", 1 ); $request->apiId = $apiId; $request->requestEntity = $param; // --------------------------构造结果---------------------------------- $result = new UmengUappEventParamGetValueListResult(); $syncAPIClient->send ( $request, $result, $reqPolicy ); $result = self::object_array($result); sort($result); return $result[1]['paramInfos']; // ----------------------------example end------------------------------------- } catch ( OceanException $ex ) { echo "Exception occured with code["; echo $ex->getErrorCode (); echo "] message ["; echo $ex->getMessage (); echo "]."; } } /** * 获取新增账号 * @param appKey * @param startDate * @param endDate * @param string periodType 查询类型(按日daily,按周weekly,按月monthly 查询) */ private function NewAccounts($data){ // --------------------------构造参数---------------------------------- $appKey = $data['appKey']; $channel = $data['channel']?$data['channel']:''; $param = new UmengUappGetNewAccountsParam(); $param->setAppkey($appKey); $param->setStartDate($data['startDate']); $param->setEndDate($data['endDate']); $param->setPeriodType($data['periodType']); //可不传 $param->setChannel($channel); return $param; } //app打开次数 private function AppOpen($data){ $appKey = $data['appKey']; $channel = $data['channel']?$data['channel']:''; $version = $data['version']?$data['version']:''; $param = new UmengUappGetLaunchesByChannelOrVersionParam(); $param->setAppkey($appKey); $param->setStartDate($data['startDate']); $param->setEndDate($data['endDate']); $param->setPeriodType($data['periodType']); $param->setChannels($channel); $param->setVersions($version); return $param; } }