Ei kuvausta

Umeng.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/9/14
  6. * Time: 11:38
  7. */
  8. include_once ('Umeng/com/umeng/uapp/param/UmengUappGetNewAccountsParam.class.php');
  9. include_once ('Umeng/com/umeng/uapp/param/UmengUappGetNewAccountsResult.class.php');
  10. include_once ('Umeng/com/umeng/uapp/param/UmengUappDateCountInfo.class.php');
  11. include_once ('Umeng/com/alibaba/openapi/client/policy/RequestPolicy.class.php');
  12. include_once ('Umeng/com/alibaba/openapi/client/entity/ByteArray.class.php');
  13. include_once ('Umeng/com/alibaba/openapi/client/util/DateUtil.class.php');
  14. include_once ('Umeng/com/alibaba/openapi/client/policy/ClientPolicy.class.php');
  15. include_once ('Umeng/com/alibaba/openapi/client/policy/ClientPolicy.class.php');
  16. include_once ('Umeng/com/alibaba/openapi/client/APIRequest.class.php');
  17. include_once ('Umeng/com/alibaba/openapi/client/APIId.class.php');
  18. include_once ('Umeng/com/alibaba/openapi/client/SyncAPIClient.class.php');
  19. class Umeng{
  20. protected $apiKey;
  21. protected $apiSecurity;
  22. public function setApiKey(){
  23. $this->apiKey = config('constants.UmengApiKey');
  24. $this->apiSecurity = config('constants.UmengApiSecurity');
  25. }
  26. private function UmengRequest(){
  27. $reqPolicy = new RequestPolicy ();
  28. $reqPolicy->httpMethod = "POST";
  29. $reqPolicy->needAuthorization = false;
  30. $reqPolicy->requestSendTimestamp = false;
  31. // 测试环境只支持http
  32. $reqPolicy->useHttps = false;
  33. //$reqPolicy->useHttps = true;
  34. $reqPolicy->useSignture = true;
  35. $reqPolicy->accessPrivateApi = false;
  36. return $reqPolicy;
  37. }
  38. public function getDayNews($data){
  39. try {
  40. $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com');
  41. $syncAPIClient = new SyncAPIClient ($clientPolicy);
  42. $reqPolicy = new RequestPolicy ();
  43. $reqPolicy->httpMethod = "POST";
  44. $reqPolicy->needAuthorization = false;
  45. $reqPolicy->requestSendTimestamp = false;
  46. // 测试环境只支持http
  47. // $reqPolicy->useHttps = false;
  48. $reqPolicy->useHttps = true;
  49. $reqPolicy->useSignture = true;
  50. $reqPolicy->accessPrivateApi = false;
  51. $param = new UmengUappGetNewAccountsParam();
  52. $param->setAppkey($data['appKey']);
  53. $param->setStartDate($data['startDate']);
  54. $param->setEndDate($data['endDate']);
  55. $param->setPeriodType($data['type']);
  56. $param->setChannel($data['channel']);
  57. $request = new APIRequest ();
  58. $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.getNewAccounts", 1);
  59. $request->apiId = $apiId;
  60. $request->requestEntity = $param;
  61. $result = new UmengUappGetNewAccountsResult();
  62. $syncAPIClient->send($request, $result, $reqPolicy);
  63. $result = self::object_array($result);
  64. sort($result);
  65. return $result[2]['newAccountInfo'][0]['newUser'];
  66. }catch (OceanException $ex){
  67. echo "Exception occured with code[";
  68. echo $ex->getErrorCode ();
  69. echo "] message [";
  70. echo $ex->getMessage ();
  71. echo "].";
  72. }
  73. }
  74. public function getChannelData($data){
  75. try {
  76. // ---------------------------example start---------------------------------
  77. // 请替换第一个参数apiKey和第二个参数apiSecurity
  78. $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com');
  79. $syncAPIClient = new SyncAPIClient ( $clientPolicy );
  80. $reqPolicy = new RequestPolicy ();
  81. $reqPolicy->httpMethod = "POST";
  82. $reqPolicy->needAuthorization = false;
  83. $reqPolicy->requestSendTimestamp = false;
  84. // 测试环境只支持http
  85. // $reqPolicy->useHttps = false;
  86. $reqPolicy->useHttps = true;
  87. $reqPolicy->useSignture = true;
  88. $reqPolicy->accessPrivateApi = false;
  89. // --------------------------构造参数----------------------------------
  90. $param = new UmengUappGetChannelDataParam();
  91. $param->setAppkey($data['appKey']);
  92. $param->setDate($data['lastData']);
  93. $param->setPerPage('100');
  94. $param->setPage('1');
  95. // --------------------------构造请求----------------------------------
  96. $request = new APIRequest ();
  97. $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.getChannelData", 1 );
  98. $request->apiId = $apiId;
  99. $request->requestEntity = $param;
  100. // --------------------------构造结果----------------------------------
  101. $result = new UmengUappGetChannelDataResult();
  102. $syncAPIClient->send ( $request, $result, $reqPolicy );
  103. $syncAPIClient->send($request, $result, $reqPolicy);
  104. $result = self::object_array($result);
  105. sort($result);
  106. return $result[3];
  107. // ----------------------------example end-------------------------------------
  108. } catch ( OceanException $ex ) {
  109. echo "Exception occured with code[";
  110. echo $ex->getErrorCode ();
  111. echo "] message [";
  112. echo $ex->getMessage ();
  113. echo "].";
  114. }
  115. }
  116. /**
  117. * 获取友盟数据
  118. * @param $data
  119. * @throws Exception
  120. */
  121. public function getUmengResponse($data){
  122. try {
  123. include_once ('Umeng/com/umeng/uapp/param/UmengUappEventGetUniqueUsersParam.class.php');
  124. include_once ('Umeng/com/umeng/uapp/param/UmengUappEventGetUniqueUsersResult.class.php');
  125. // ---------------------------example start---------------------------------
  126. // 请替换第一个参数apiKey和第二个参数apiSecurity
  127. $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com');
  128. $syncAPIClient = new SyncAPIClient ( $clientPolicy );
  129. $reqPolicy = new RequestPolicy ();
  130. $reqPolicy->httpMethod = "POST";
  131. $reqPolicy->needAuthorization = false;
  132. $reqPolicy->requestSendTimestamp = false;
  133. // 测试环境只支持http
  134. // $reqPolicy->useHttps = false;
  135. $reqPolicy->useHttps = true;
  136. $reqPolicy->useSignture = true;
  137. $reqPolicy->accessPrivateApi = false;
  138. // --------------------------构造参数----------------------------------
  139. $param = new UmengUappEventGetUniqueUsersParam();
  140. $param->setAppkey($data['appKey']);
  141. $param->setStartDate($data['startDate']);
  142. $param->setEndDate($data['endDate']);
  143. $param->setEventName($data['event']);
  144. // --------------------------构造请求----------------------------------
  145. $request = new APIRequest ();
  146. $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.event.getUniqueUsers", 1 );
  147. $request->apiId = $apiId;
  148. $request->requestEntity = $param;
  149. // --------------------------构造结果----------------------------------
  150. $result = new UmengUappEventGetUniqueUsersResult();
  151. $syncAPIClient->send ( $request, $result, $reqPolicy );
  152. $result = self::object_array($result);
  153. sort($result);
  154. return $result[2]['uniqueUsers'];
  155. // ----------------------------example end-------------------------------------
  156. } catch ( OceanException $ex ) {
  157. return false;
  158. echo "Exception occured with code[";
  159. echo $ex->getErrorCode ();
  160. echo "] message [";
  161. echo $ex->getMessage ();
  162. echo "].";
  163. }
  164. }
  165. public static function object_array($array) {
  166. if(is_object($array)) {
  167. $array = (array)$array;
  168. } if(is_array($array)) {
  169. foreach($array as $key=>$value) {
  170. $array[$key] = self::object_array($value);
  171. }
  172. }
  173. return $array;
  174. }
  175. public function getAppList($data){
  176. try{
  177. include_once ('Umeng/com/umeng/uapp/param/UmengUappGetAppListParam.class.php');
  178. include_once ('Umeng/com/umeng/uapp/param/UmengUappGetAppListResult.class.php');
  179. $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com');
  180. $syncAPIClient = new SyncAPIClient ( $clientPolicy );
  181. $reqPolicy = new RequestPolicy ();
  182. $reqPolicy->httpMethod = "POST";
  183. $reqPolicy->needAuthorization = false;
  184. $reqPolicy->requestSendTimestamp = false;
  185. // 测试环境只支持http
  186. // $reqPolicy->useHttps = false;
  187. $reqPolicy->useHttps = true;
  188. $reqPolicy->useSignture = true;
  189. $reqPolicy->accessPrivateApi = false;
  190. // --------------------------构造参数----------------------------------
  191. $param = new UmengUappGetAppListParam();
  192. $param->setPage($data['page']);
  193. $param->setPerPage($data['perPage']);
  194. // --------------------------构造请求----------------------------------
  195. $request = new APIRequest ();
  196. $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.getAppList", 1 );
  197. $request->apiId = $apiId;
  198. $request->requestEntity = $param;
  199. // --------------------------构造结果----------------------------------
  200. $result = new UmengUappGetAppListResult();
  201. $syncAPIClient->send ( $request, $result, $reqPolicy );
  202. $result = self::object_array($result);
  203. sort($result);
  204. return $result[3]['appInfos'];
  205. // ----------------------------example end-------------------------------------
  206. } catch ( OceanException $ex ) {
  207. return false;
  208. echo "Exception occured with code[";
  209. echo $ex->getErrorCode ();
  210. echo "] message [";
  211. echo $ex->getMessage ();
  212. echo "].";
  213. }
  214. }
  215. public function getTypeApp($data){
  216. try {
  217. // ---------------------------example start---------------------------------
  218. include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetDataParam.class.php');
  219. include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetDataResult.class.php');
  220. // 请替换第一个参数apiKey和第二个参数apiSecurity
  221. $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com');
  222. $syncAPIClient = new SyncAPIClient ( $clientPolicy );
  223. $reqPolicy = new RequestPolicy ();
  224. $reqPolicy->httpMethod = "POST";
  225. $reqPolicy->needAuthorization = false;
  226. $reqPolicy->requestSendTimestamp = false;
  227. // 测试环境只支持http
  228. // $reqPolicy->useHttps = false;
  229. $reqPolicy->useHttps = true;
  230. $reqPolicy->useSignture = true;
  231. $reqPolicy->accessPrivateApi = false;
  232. // --------------------------构造参数----------------------------------
  233. $param = new UmengUappEventParamGetDataParam();
  234. $param->setAppkey($data['appKey']);
  235. $param->setStartDate($data['startDate']);
  236. $param->setEndDate($data['endDate']);
  237. $param->setEventName($data['eventName']);
  238. $param->setEventParamName($data['eventName']);
  239. $param->setParamValueName($data['type']);
  240. // --------------------------构造请求----------------------------------
  241. $request = new APIRequest ();
  242. $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.event.param.getData", 1 );
  243. $request->apiId = $apiId;
  244. $request->requestEntity = $param;
  245. // --------------------------构造结果----------------------------------
  246. $result = new UmengUappEventParamGetDataResult();
  247. $syncAPIClient->send ( $request, $result, $reqPolicy );
  248. $result = self::object_array($result);
  249. sort($result);
  250. return $result[2]['paramValueData'];
  251. // ----------------------------example end-------------------------------------
  252. } catch ( OceanException $ex ) {
  253. return false;
  254. echo "Exception occured with code[";
  255. echo $ex->getErrorCode ();
  256. echo "] message [";
  257. echo $ex->getMessage ();
  258. echo "].";
  259. }
  260. }
  261. public function getValueList($data){
  262. try {
  263. // ---------------------------example start---------------------------------
  264. include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetValueListParam.class.php');
  265. include_once ('Umeng/com/umeng/uapp/param/UmengUappEventParamGetValueListResult.class.php');
  266. // 请替换第一个参数apiKey和第二个参数apiSecurity
  267. $clientPolicy = new ClientPolicy ($this->apiKey, $this->apiSecurity, 'gateway.open.umeng.com');
  268. $syncAPIClient = new SyncAPIClient ( $clientPolicy );
  269. $reqPolicy = new RequestPolicy ();
  270. $reqPolicy->httpMethod = "POST";
  271. $reqPolicy->needAuthorization = false;
  272. $reqPolicy->requestSendTimestamp = false;
  273. // 测试环境只支持http
  274. // $reqPolicy->useHttps = false;
  275. $reqPolicy->useHttps = true;
  276. $reqPolicy->useSignture = true;
  277. $reqPolicy->accessPrivateApi = false;
  278. // --------------------------构造参数----------------------------------
  279. $param = new UmengUappEventParamGetValueListParam();
  280. $param->setAppkey($data['appKey']);
  281. $param->setStartDate($data['startDate']);
  282. $param->setEndDate($data['endDate']);
  283. $param->setEventName($data['eventName']);
  284. $param->setEventParamName($data['eventName']);
  285. // --------------------------构造请求----------------------------------
  286. $request = new APIRequest ();
  287. $apiId = new APIId ("com.umeng.uapp", "umeng.uapp.event.param.getValueList", 1 );
  288. $request->apiId = $apiId;
  289. $request->requestEntity = $param;
  290. // --------------------------构造结果----------------------------------
  291. $result = new UmengUappEventParamGetValueListResult();
  292. $syncAPIClient->send ( $request, $result, $reqPolicy );
  293. $result = self::object_array($result);
  294. sort($result);
  295. return $result[1]['paramInfos'];
  296. // ----------------------------example end-------------------------------------
  297. } catch ( OceanException $ex ) {
  298. echo "Exception occured with code[";
  299. echo $ex->getErrorCode ();
  300. echo "] message [";
  301. echo $ex->getMessage ();
  302. echo "].";
  303. }
  304. }
  305. /**
  306. * 获取新增账号
  307. * @param appKey
  308. * @param startDate
  309. * @param endDate
  310. * @param string periodType 查询类型(按日daily,按周weekly,按月monthly 查询)
  311. */
  312. private function NewAccounts($data){
  313. // --------------------------构造参数----------------------------------
  314. $appKey = $data['appKey'];
  315. $channel = $data['channel']?$data['channel']:'';
  316. $param = new UmengUappGetNewAccountsParam();
  317. $param->setAppkey($appKey);
  318. $param->setStartDate($data['startDate']);
  319. $param->setEndDate($data['endDate']);
  320. $param->setPeriodType($data['periodType']);
  321. //可不传
  322. $param->setChannel($channel);
  323. return $param;
  324. }
  325. //app打开次数
  326. private function AppOpen($data){
  327. $appKey = $data['appKey'];
  328. $channel = $data['channel']?$data['channel']:'';
  329. $version = $data['version']?$data['version']:'';
  330. $param = new UmengUappGetLaunchesByChannelOrVersionParam();
  331. $param->setAppkey($appKey);
  332. $param->setStartDate($data['startDate']);
  333. $param->setEndDate($data['endDate']);
  334. $param->setPeriodType($data['periodType']);
  335. $param->setChannels($channel);
  336. $param->setVersions($version);
  337. return $param;
  338. }
  339. }