PHP code example of moyi / umeng-open-api

1. Go to this page and download the library: Download moyi/umeng-open-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moyi / umeng-open-api example snippets




...
use moyi\client\APIId;
use moyi\client\APIRequest;
use moyi\client\SyncAPIClient;
use moyi\client\policy\ClientPolicy;
use moyi\client\policy\RequestPolicy;
use moyi\umeng\uapp\param\UmengUappGetNewUsersParam;
use moyi\umeng\uapp\param\UmengUappGetNewUsersResult;

public function getUmengData() {
  $date = now()->toDateString();

  $clientPolicy = new ClientPolicy(
      config('your umeng key'),
      config('your umeng secret'),
      'gateway.open.umeng.com'
  );
  
  $syncAPIClient = new SyncAPIClient($clientPolicy);
  
  $reqPolicy                       = new RequestPolicy();
  $reqPolicy->useHttps             = true;
  $reqPolicy->requestSendTimestamp = false;
  
  $param = new UmengUappGetNewUsersParam();
  $param->setAppkey('your umeng app key');
  $param->setStartDate($date);
  $param->setEndDate($date);
  
  $request = new APIRequest();
  $apiId   = new APIId(
      "com.umeng.uapp",
      "umeng.uapp.getNewUsers",
      1
  );
  
  $request->apiId         = $apiId;
  $request->requestEntity = $param;
  
  $result = new UmengUappGetNewUsersResult();
  
  $syncAPIClient->send($request, $result, $reqPolicy);
  
  $res  = $result->getNewUserInfo();
  $data = $res[0]->getValue() ?? 0;
}