main.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* @var $this \yii\web\View */
  3. /* @var $content string */
  4. use yii\helpers\Html;
  5. use company\assets\wechat\AppAsset;
  6. AppAsset::register($this);
  7. $wechat = new \common\library\WeChat();
  8. $timestamp = time();
  9. $noncestr = rand('10000','99999');
  10. ?>
  11. <?php $this->beginPage() ?>
  12. <!DOCTYPE html>
  13. <html lang="<?= Yii::$app->language ?>">
  14. <head>
  15. <meta charset="UTF-8">
  16. <meta charset="<?= Yii::$app->charset ?>">
  17. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  18. <?= Html::csrfMetaTags() ?>
  19. <title><?= Html::encode($this->title) ?></title>
  20. <?php $this->head() ?>
  21. </head>
  22. <body>
  23. <?=Html::jsFile('@web/js/jweixin-1.0.0.js');?>
  24. <script>
  25. wx.config({
  26. debug: false,
  27. appId: '<?php echo Yii::$app->params['wechat']['appID'] ?>', // 必填,公众号的唯一标识
  28. timestamp:<?php echo $timestamp?>, // 必填,生成签名的
  29. nonceStr: '<?php echo $noncestr; ?>', // 必填,生成签名的
  30. signature: '<?php echo $wechat->getsignature($noncestr,$timestamp,Yii::$app->request->hostInfo.Yii::$app->request->getUrl());?>',
  31. jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','hideOptionMenu','chooseImage','previewImage','uploadImage','downloadImage','showMenuItems','startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice']
  32. });
  33. wx.ready(function() {
  34. wx.showMenuItems({
  35. menuList: ["menuItem:favorite"] // 要显示的菜单项,所有menu项见附录3
  36. });
  37. wx.hideOptionMenu();
  38. });
  39. </script>
  40. <?php $this->beginBody() ?>
  41. <?php if(Yii::$app->getSession()->hasFlash('success')): ?>
  42. <script>
  43. $.alert('<?=Yii::$app->session->getFlash('success');?>');
  44. </script>
  45. <?php endif;?>
  46. <?php if(Yii::$app->getSession()->hasFlash('error')): ?>
  47. <script>
  48. $.alert('<?=Yii::$app->session->getFlash('error');?>','警告');
  49. </script>
  50. <?php endif;?>
  51. <?= $content ?>
  52. <?php $this->endBody() ?>
  53. </body>
  54. </html>
  55. <?php $this->endPage() ?>