123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2018/9/14
- * Time: 11:38
- */
- include_once ('Umeng/com/umeng/uapp/param/UmengUappGetNewAccountsParam.class.php');
- include_once ('Umeng/com/umeng/uapp/param/UmengUappGetNewAccountsResult.class.php');
- include_once ('Umeng/com/umeng/uapp/param/UmengUappDateCountInfo.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/policy/RequestPolicy.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/entity/ByteArray.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/util/DateUtil.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/policy/ClientPolicy.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/policy/ClientPolicy.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/APIRequest.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/APIId.class.php');
- include_once ('Umeng/com/alibaba/openapi/client/SyncAPIClient.class.php');
- class Umeng{
- protected $apiKey;
- protected $apiSecurity;
- public function setApiKey(){
- $this->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;
- }
- }
|