| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | <?php/** * MpOpenMkt.php UTF-8 * * * @date    : 2021-02-24 14:31 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : luowei <lw@huosdk.com> * @version : HUOSDK 9.0 */namespace huoMpAd;use huolib\constant\MpConfConst;use huolib\status\CommonStatus;use huomp\model\weixin\MpConfModel;use think\Log;class MpOpenMkt extends MpAdOut {    /**     * 数据上报     *     * @param $app_id     * @param $action_data     *     * @return array     */    public function dataReport($app_id, $action_data) {        $_mc_model = new MpConfModel();        $_conf_data = $_mc_model->getDataByAppId($app_id, MpConfConst::MP_CONF_TYPE_6);        if (empty($_conf_data)) {            $_code = CommonStatus::DATA_NOT_FOUND_EXCEPTION;            Log::write(                "func=".__FUNCTION__."&class=".__CLASS__."&step=1&app_id=".$app_id."&type="                .MpConfConst::MP_CONF_TYPE_6."&code=".$_code.'&msg=conf'.CommonStatus::getMsg($_code),                LOG::ERROR, true            );            return $this->huoError($_code, CommonStatus::getMsg($_code));        }        $this->conf_id = $_conf_data['id'];        $this->wx_app_id = $_conf_data['mp_id'];        $this->wx_app_secret = $_conf_data['app_secret'];        if (empty($this->wx_app_id) || empty($this->wx_app_secret)) {            $_code = CommonStatus::INVALID_PARAMS;            Log::write(                "func=".__FUNCTION__."&class=".__CLASS__."&step=2&app_id=".$app_id."&type="                .MpConfConst::MP_CONF_TYPE_6."&code=".$_code.'&msg=conf'.CommonStatus::getMsg($_code).'&wx_app_id='                .$this->wx_app_id.'&app_secret='.$this->wx_app_secret,                LOG::ERROR, true            );            return $this->huoError($_code, CommonStatus::getMsg($_code));        }        $_param = [            'actions' => [[                              'user_action_set_id' => $action_data['user_action_set_id'],                              'action_time'        => time(),                              'action_type'        => $action_data['action_type'],                              'user_id'            => [                                  'wechat_app_id' => $this->wx_app_id,                                  'wechat_openid' => $action_data['openid'],                              ],                              'action_param' => [                                  'claim_type' => 0,                                  'source' => 0,                                  'value' => $action_data['action_param_value'],                              ],                          ]]        ];        $_rs = (new MpAdApi())->dataReport($this->wx_app_id, $this->wx_app_secret, $_param);        if (CommonStatus::NO_ERROR != $_rs['code']) {            $_code = CommonStatus::UNKNOWN_ERROR;            $_param = json_encode([$_conf_data['mp_id'], $_conf_data['app_secret'], $_param]);            $_return = json_encode($_rs);            Log::write(                "func=".__FUNCTION__."&class=".__CLASS__."&step=3&app_id=".$app_id."&type="                .MpConfConst::MP_CONF_TYPE_6."&code=".$_code.'&msg=conf'.CommonStatus::getMsg($_code).'¶m='                .$_param.'&return='.$_return,                LOG::ERROR, true            );            return $this->huoError($_code, CommonStatus::getMsg($_code));        }        $_code = CommonStatus::NO_ERROR;        return $this->huoSuccess($_code, CommonStatus::getMsg($_code));    }    public function getDataSourceReport($app_id, $start_date, $end_date) {        $_mc_model = new MpConfModel();        $_conf_data = $_mc_model->getDataByAppId($app_id, MpConfConst::MP_CONF_TYPE_6);        if (empty($_conf_data)) {            $_code = CommonStatus::DATA_NOT_FOUND_EXCEPTION;            Log::write(                "func=".__FUNCTION__."&class=".__CLASS__."&step=1&app_id=".$app_id."&type="                .MpConfConst::MP_CONF_TYPE_6."&code=".$_code.'&msg=conf'.CommonStatus::getMsg($_code),                LOG::ERROR, true            );            return $this->huoError($_code, CommonStatus::getMsg($_code));        }        $this->wx_app_id = $_conf_data['mp_id'];        $this->wx_app_secret = $_conf_data['app_secret'];        if (empty($this->wx_app_id) || empty($this->wx_app_secret)) {            $_code = CommonStatus::INVALID_PARAMS;            Log::write(                "func=".__FUNCTION__."&class=".__CLASS__."&step=2&app_id=".$app_id."&type="                .MpConfConst::MP_CONF_TYPE_6."&code=".$_code.'&msg=conf'.CommonStatus::getMsg($_code).'&wx_app_id='                .$this->wx_app_id.'&app_secret='.$this->wx_app_secret,                LOG::ERROR, true            );            return $this->huoError($_code, CommonStatus::getMsg($_code));        }        $_rs = $this->createDataSource($app_id);        if (CommonStatus::NO_ERROR != $_rs['code']) {            $_msg = '创建数据源错误:'.$_rs['msg'];            $_code = CommonStatus::INNER_ERROR;            return $this->huoError($_code, $_msg);        }        $_user_action_set_id = $_rs['data']['user_action_set_id'];        $_param = [              'user_action_set_id' => $_user_action_set_id,//                              'time_granularity' => 'DAILY',//                              'aggregation' => 'ACTION_TYPE',              'date_range' => json_encode([                  'start_date' => $start_date,                  'end_date' => $end_date,              ], JSON_UNESCAPED_UNICODE),        ];        $_rs = (new MpAdApi())->getDataSourceReport($this->wx_app_id, $this->wx_app_secret, $_param);        if (CommonStatus::NO_ERROR != $_rs['code']) {            $_code = CommonStatus::UNKNOWN_ERROR;            $_param = json_encode([$_conf_data['mp_id'], $_conf_data['app_secret'], $_param]);            $_return = json_encode($_rs);            Log::write(                "func=".__FUNCTION__."&class=".__CLASS__."&step=3&app_id=".$app_id."&type="                .MpConfConst::MP_CONF_TYPE_6."&code=".$_code.'&msg=conf'.CommonStatus::getMsg($_code).'¶m='                .$_param.'&return='.$_return,                LOG::ERROR, true            );            return $this->huoError($_code, CommonStatus::getMsg($_code));        }        $_code = CommonStatus::NO_ERROR;        return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rs['data']);    }}
 |