查看: 729|回复: 0

微擎通过jssdk自定义分享设置方法

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2024-5-25 19:58:59 | 显示全部楼层 |阅读模式
在做微信开发时自定义分享设置是一个很常见并且实力的功能需求。通常地会把设置的标题,描述,链接,图片等设置集成在参数设置里面。
以下是模板层的示例代码:
  1. <html>
  2. <head>
  3.     <title>测试 register_jssdk</title>
  4.     {php echo register_jssdk(true);} <!-- 放到其他引入的 js 之前 -->
  5. </head>

  6. <body>
  7.     <script>
  8.     wx.ready(function () {
  9.         sharedata = {
  10.             title: '微信JS-SDK Demo',
  11.             desc: '微信JS-SDK,帮助第三方为用户提供更优质的移动web服务',
  12.             link: 'http://demo.open.weixin.qq.com/jssdk/',//本域链接
  13.             imgUrl: 'http://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0',//本域链接
  14.             /*
  15.             success: function(){
  16.            
  17.                 alert('success');
  18.             },
  19.             cancel: function(){
  20.                 alert('cancel');
  21.             }
  22.              */
  23.         };
  24.                         wx.onMenuShareAppMessage(sharedata);
  25.                         wx.onMenuShareTimeline(sharedata);
  26.                         wx.onMenuShareQQ(sharedata);
  27.                         wx.onMenuShareQZone(sharedata);
  28.                         wx.onMenuShareWeibo(sharedata);
  29. //更多调用,查官方文档

  30.     });
  31.     </script>
  32. </body>
  33. </html>
复制代码
记录一个示例:template
  1. {php echo register_jssdk();}
  2. <script type="text/javascript">
  3.     wx.ready(function () {
  4.         sharedata = {
  5.             title: "{php echo $this->module['config']['stitle']}",
  6.             desc: "{php echo $this->module['config']['sinfo']}",
  7.             link: "{php echo $_W['siteroot'].$this->createMobileUrl('into')}",
  8.             imgUrl: "{php echo $_W['attachurl'].$this->module['config']['simg']}",

  9.         };

  10.                         wx.onMenuShareAppMessage(sharedata);
  11.                         wx.onMenuShareTimeline(sharedata);
  12.                         wx.onMenuShareQQ(sharedata);
  13.                         wx.onMenuShareQZone(sharedata);
  14.                         wx.onMenuShareWeibo(sharedata);

  15.     });
  16.     </script>
复制代码
module.php
  1. public function settingsDisplay($settings) {
  2.                 global $_W, $_GPC;
  3.                 load()->func('tpl');
  4.                 //点击模块设置时将调用此方法呈现模块设置页面,$settings 为模块设置参数, 结构为数组。这个参数系统针对不同公众账号独立保存。
  5.                 //在此呈现页面中自行处理post请求并保存设置参数(通过使用$this->saveSettings()来实现)
  6.                 if(checksubmit('setting')) {
  7.                         $this->saveSettings($_GPC['data']);
  8.                         message('修改成功','refresh', 'success');
  9.                 }else{
  10.                         include $this->template('setting');
  11.                 }

  12.                
  13.         }
复制代码
setting.html
  1. {template 'common/header'}
  2. {php load()->func('tpl');}
  3. <div class="panel panel-default">
  4.   <div class="panel-heading">
  5.     <h3 class="panel-title">吸粉设置</h3>
  6.   </div>
  7.   <div class="panel-body">
  8.     <form class="form-horizontal" method="post" enctype="multipart/form-data">
  9.   <div class="form-group">
  10.     <label for="inputPassword3" class="col-sm-2 control-label">二维码</label>
  11.     <div class="col-sm-10">
  12.                 {php echo tpl_form_field_image('data[ewm]',$this->module['config']['ewm'])}
  13.     </div>
  14.   </div>
  15.   <div class="form-group">
  16.   <label for="inputPassword3" class="col-sm-2 control-label"></label>
  17.       <div class="col-sm-10">
  18.         <div class="alert alert-warning alert-dismissible" role="alert">
  19.   <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
  20.   <strong>注意:</strong> 请将二维码图片尺寸调整为120*120后再上传,否则会错位
  21. </div>
  22.     </div>
  23.         </div>

  24.   <div class="form-group">
  25.     <label for="inputPassword3" class="col-sm-2 control-label">分享标题</label>
  26.     <div class="col-sm-10">
  27.                 <input type="text" class="form-control" name="data[stitle]" value="{php echo $this->module['config']['stitle']}"/>
  28.     </div>
  29.   </div>
  30.    <div class="form-group">
  31.     <label for="inputPassword3" class="col-sm-2 control-label">分享描述</label>
  32.     <div class="col-sm-10">
  33.                 <input type="text" class="form-control" name="data[sinfo]" value="{php echo $this->module['config']['sinfo']}"/>
  34.     </div>
  35.   </div>
  36.    <div class="form-group">
  37.     <label for="inputPassword3" class="col-sm-2 control-label">分享图片</label>
  38.     <div class="col-sm-10">
  39.                 {php echo tpl_form_field_image('data[simg]',$this->module['config']['simg'])}
  40.     </div>
  41.   </div>
  42.       
  43.       
  44.   <div class="form-group">
  45.     <div class="col-sm-offset-2 col-sm-10">
  46.       <input type="submit" value="保存" name="setting" class="btn btn-default" />
  47.           <input type="hidden" name="token" value="{$_W['token']}" />
  48.     </div>
  49.   </div>
  50. </form>
  51.   </div>
  52. </div>
  53. {template 'common/footer'}
复制代码
需要注意的是,register_jssdk()会自动识别,或为普通公众号可以在后台设置借权操作。分享的链接与图片地址必须为本域下的,否则无法显示。

道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部