| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 | 
							- <?php
 
- /**
 
-  * MpAdApi.php  UTF-8
 
-  * 广告行为数据上报接口
 
-  *
 
-  * @date    : 2018/11/16 11:08
 
-  *
 
-  * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 
-  * @author  : chenbingling <cbl@huosdk.com>
 
-  * @version : HuoMp 1.0
 
-  */
 
- namespace huoMpAd;
 
- use huo\controller\common\Base;
 
- use huoMpMsg\controller\Common;
 
- use huoMpMsg\status\OfficialAccountStatus;
 
- class MpAdApi extends Base {
 
-     /**
 
-      * 创建数据源
 
-      *
 
-      * @param string $wx_app_id     第三方用户唯一凭证
 
-      * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
 
-      * @param array  $data          请求参数
 
-      *
 
-      * @return array
 
-      */
 
-     public function createDataSource($wx_app_id, $wx_app_secret, $data) {
 
-         $_url = 'https://api.weixin.qq.com/marketing/user_action_sets/add?version=v1.0';
 
-         $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
 
-         $_url = $_url.'&access_token='.$_access_token;
 
-         $_param = json_encode($data, JSON_UNESCAPED_UNICODE);
 
-         $_header = ['Content-Type: application/json; charset=utf-8'];
 
-         $_ret = Common::curl($_url, $_param, 'POST', $_header);
 
-         $_rdata = [];
 
-         if (Common::isJson($_ret)) {
 
-             $_rdata = json_decode($_ret, true);
 
-         }
 
-         if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
 
-             $_code = $_rdata['errcode'];
 
-             return $this->huoError($_code, $_rdata['errmsg']);
 
-         }
 
- //        $_rdata['data'] = [
 
- //            'user_action_set_id' => '9999999'
 
- //        ];
 
-         $_code = OfficialAccountStatus::NO_ERROR;
 
-         return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata['data']);
 
-     }
 
-     /**
 
-      * 回传数据
 
-      *
 
-      * @param string $wx_app_id     第三方用户唯一凭证
 
-      * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
 
-      * @param array  $data          请求参数
 
-      * @param bool   $read_cache
 
-      *
 
-      * @return array
 
-      */
 
-     public function dataReport($wx_app_id, $wx_app_secret, $data, $read_cache = true) {
 
-         $_url = 'https://api.weixin.qq.com/marketing/user_actions/add?version=v1.0';
 
-         $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret, $read_cache);
 
-         $_url = $_url.'&access_token='.$_access_token;
 
-         $_param = json_encode($data, JSON_UNESCAPED_UNICODE);
 
-         $_header = ['Content-Type: application/json; charset=utf-8'];
 
-         $_ret = Common::curl($_url, $_param, 'POST', $_header);
 
-         $_rdata = [];
 
-         if (Common::isJson($_ret)) {
 
-             $_rdata = json_decode($_ret, true);
 
-         }
 
-         if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
 
-             if ($_rdata['errcode'] == '40001' && $read_cache) {
 
-                 return $this->dataReport($wx_app_id, $wx_app_secret, $data,false);
 
-             }
 
-             $_code = $_rdata['errcode'];
 
-             return $this->huoError($_code, $_rdata['errmsg']);
 
-         }
 
-         $_code = OfficialAccountStatus::NO_ERROR;
 
-         return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code));
 
-     }
 
-     /**
 
-      * 数据源报表
 
-      *
 
-      * @param string $wx_app_id     第三方用户唯一凭证
 
-      * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
 
-      * @param array  $data          请求参数
 
-      *
 
-      * @return array
 
-      */
 
-     public function getDataSourceReport($wx_app_id, $wx_app_secret, $data) {
 
-         $_url = 'https://api.weixin.qq.com/marketing/user_action_set_reports/get?version=v1.0';
 
-         $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
 
-         $_url = $_url.'&access_token='.$_access_token.'&'.http_build_query($data);
 
-         $_ret = Common::curl($_url, '', 'GET');
 
-         $_rdata = [];
 
-         if (Common::isJson($_ret)) {
 
-             $_rdata = json_decode($_ret, true);
 
-         }
 
-         if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
 
-             $_code = $_rdata['errcode'];
 
-             return $this->huoError($_code, $_rdata['errmsg']);
 
-         }
 
-         $_code = OfficialAccountStatus::NO_ERROR;
 
-         return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata['data']);
 
-     }
 
-     /**
 
-      * 数据源查询
 
-      *
 
-      * @param string $wx_app_id     第三方用户唯一凭证
 
-      * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
 
-      * @param array $data
 
-      *
 
-      * @return array
 
-      */
 
-     public function getDataSourceInfo($wx_app_id, $wx_app_secret, $data) {
 
-         $_url = 'https://api.weixin.qq.com/marketing/user_action_sets/get?version=v1.0';
 
-         $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
 
-         $_url = $_url.'&access_token='.$_access_token.'&'.http_build_query($data);
 
-         $_ret = Common::curl($_url, '', 'GET');
 
-         $_rdata = [];
 
-         if (Common::isJson($_ret)) {
 
-             $_rdata = json_decode($_ret, true);
 
-         }
 
-         if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
 
-             $_code = $_rdata['errcode'];
 
-             return $this->huoError($_code, $_rdata['errmsg']);
 
-         }
 
-         $_code = OfficialAccountStatus::NO_ERROR;
 
-         return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata['data']);
 
-     }
 
- }
 
 
  |