MpWeiXin.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\api\controller;
  4. use app\common\service\MpWxService;
  5. use app\store\model\analysis\AnalysisDailyVisit;
  6. /**
  7. * 微信小程序
  8. * @package app\api\controller
  9. */
  10. class MpWeiXin extends Controller
  11. {
  12. //小程序分享图
  13. public function qrCode(){
  14. $path = $this->request->get('path');
  15. $path = $path ? html_entity_decode($path) : '';
  16. $weixinToken = MpWxService::weixinTokenCache();
  17. $accessToken = $weixinToken['access_token'];
  18. $url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=".$accessToken;
  19. if(empty($path)){
  20. $path = 'pages/tabBar/index/index';
  21. }
  22. $params["path"] = $path;
  23. $params['is_hyaline'] = true;//是否需要透明底色,为 true 时,生成透明底色的小程序码
  24. $params['width'] = 600;//二维码的宽度,单位 px。最小 280px,最大 1280px ,默认430
  25. $serve_env = env('SERVE_ENV');
  26. $env_version = $serve_env == 'test' ? 'trial' : 'release'; // 要打开的小程序版本,正式版:release,体验版:trial,开发版:develop
  27. $params['env_version'] = $env_version;
  28. $ret = curl_post($url,json_encode($params));
  29. $arr = json_decode($ret);
  30. if(isset($arr->errcode)&&$arr->errcode==40001){
  31. MpWxService::delweixinTokenCache();
  32. }
  33. ob_clean();
  34. return response($ret,200, ['content-type' => 'image/png']);
  35. }
  36. public function visit()
  37. {
  38. $weixinToken = MpWxService::weixinTokenCache();
  39. $accessToken = $weixinToken['access_token'];
  40. $url = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=".$accessToken;
  41. // $url = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo?access_token=".$accessToken;
  42. // $url = "https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage?access_token=".$accessToken;
  43. // $url = "https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend?access_token=".$accessToken;
  44. $params['begin_date'] = '20220323';
  45. $params['end_date'] = '20220323';
  46. $ret = curl_post($url,json_encode($params));
  47. $arr = json_decode($ret);
  48. if(isset($arr->errcode)&&$arr->errcode==40001){
  49. MpWxService::delweixinTokenCache();
  50. }
  51. dd($arr);
  52. }
  53. public function dailyVisit()
  54. {
  55. $res = AnalysisDailyVisit::addDailyInitVisit();
  56. dd($res);
  57. }
  58. }