MpAdReportController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * MpAdReportController.php UTF-8
  4. * 小程序广告转化行为数据接入
  5. *
  6. * @date : 2018/11/16 10:23
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace mini\sdk\controller;
  13. use huolib\status\CommonStatus;
  14. use huoMpAd\MpAdOut;
  15. use mini\common\controller\V2ApiBaseController;
  16. use think\Log;
  17. class MpAdReportController extends V2ApiBaseController {
  18. function _initialize() {
  19. parent::_initialize();
  20. // Log::write(
  21. // $this->request->scheme().'://'.$this->request->server('HTTP_HOST').$this->request->server('REQUEST_URI').'?'
  22. // .$this->request->getContent(),
  23. // Log::LOG
  24. // );
  25. }
  26. /**
  27. * 小程序广告转化行为数据上报
  28. * http://doc.huosdk.com/159?page_id=4918
  29. * 【【域名】/mp/ad/report
  30. */
  31. public function index() {
  32. $_click_id = $this->request->param('click_id/s', '');
  33. if (empty($_click_id)) {
  34. $this->success(lang('SUCCESS'));
  35. }
  36. $_game_rq = $this->setGameData();
  37. $_app_id = $_game_rq->getHAppId();
  38. $_ma_out = new MpAdOut();
  39. $_rs = $_ma_out->createDataSource($_app_id);
  40. if (CommonStatus::NO_ERROR != $_rs['code']) {
  41. $_rs['msg'] = '创建数据源错误:'.$_rs['msg'];
  42. $this->returnData($_rs);
  43. }
  44. $_action_data = [];
  45. $_action_data['user_action_set_id'] = $_rs['data']['user_action_set_id'];
  46. $_action_data['click_id'] = $_click_id;
  47. $_action_data['url'] = $this->request->param('url/s', '');
  48. if (empty($_action_data['click_id'])) {
  49. $this->error('缺少参数click_id');
  50. }
  51. if (empty($_action_data['user_action_set_id'])) {
  52. $this->error('缺少参数user_action_set_id');
  53. }
  54. if (empty($_action_data['url'])) {
  55. $_action_data['url'] = 'http://www.qq.com';
  56. }
  57. if (!(strpos($_action_data['url'], "http://www.") === 0)) {
  58. $_action_data['url'] = 'http://www.'.$_action_data['url'];
  59. }
  60. $_rs = $_ma_out->dataReport($_app_id, $_action_data);
  61. if (CommonStatus::NO_ERROR != $_rs['code']) {
  62. $_rs['msg'] = '回传数据错误:'.$_rs['msg'];
  63. $this->returnData($_rs);
  64. }
  65. $this->success(lang('SUCCESS'));
  66. }
  67. }