一个小凌乱
一个小凌乱
  • 发布:2015-02-12 11:29
  • 更新:2016-10-25 14:32
  • 阅读:3543

分享时提示“无效服务”

分类:HTML5+

感谢大神帮忙!我是参考H5+中的例子写的
我在“微信开放平台”已经注册了AppID和AppSecret,下面用“AAAAAA”、“BBBBB”代替

在manifest.json配置如下:
"plugins": {
"statics": {

            },  
            "maps": {  

            },  
            "push": {  

            },  
            "share": {/*配置应用使用分享功能,参考http://ask.dcloud.net.cn/article/27*/  

                "weixin": {  
                    "appid": "AAAAAAAAAAA",/*微信开放平台应用appid*/  
                    "appsecret": "BBBBBBBBBBBBBB",/*微信开放平台应用appsecret*/  
                    "description": "微信分享"  
                }  
            },  
            "payment": {  

            }  
        }  

页面的配置如下:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="HandheldFriendly" content="true"/>
<meta name="MobileOptimized" content="320"/>
<title>Hello H5+</title>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
var shares=null,bhref=false;
// H5 plus事件处理
function plusReady(){
// plus.webview.currentWebview().addEventListener("hide",function(){
// shareHide();
// },false);
//updateSerivces();
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
/**

  • 更新分享服务
    */
    function updateSerivces(){
    plus.share.getServices( function(s){
    shares={};
    for(var i in s){
    var t=s[i];
    shares[t.id]=t;
    }
    }, function(e){
    outSet( "获取分享服务列表失败:"+e.message );
    } );
    }
    /**
    • 分享操作
    • @param {String} id
      */
      function shareAction(id,ex) {
      console.log("id:" + id + "ex" + ex);
      var s=null;
      shareClose();
      outSet( "分享操作:" );
      if(!id||!(s=shares[id])){
      outLine( "无效的分享服务!" );
      return;
      }
      if ( s.authenticated ) {
      outLine( "---已授权---" );
      shareMessage(s,ex);
      } else {
      outLine( "---未授权---" );
      s.authorize( function(){
      shareMessage(s,ex);
      },function(e){
      outLine( "认证授权失败:"+e.code+" - "+e.message );
      });
      }
      }
      /**
    • 发送分享消息
    • @param {plus.share.ShareService} s
      */
      function shareMessage(s,ex){
      var msg={content:sharecontent.value,extra:{scene:ex}};
      if(bhref){
      msg.href=sharehref.value;
      if(sharehrefTitle&&sharehrefTitle.value!=""){
      msg.title=sharehrefTitle.value;
      }
      if(sharehrefDes&&sharehrefDes.value!=""){
      msg.content=sharehrefDes.value;
      }
      msg.thumbs=["_www/logo.png"];
      }else{
      if(pic&&pic.realUrl){
      msg.pictures=[pic.realUrl];
      }
      }
      outLine(JSON.stringify(msg));
      s.send( msg, function(){
      outLine( "分享到\""+s.description+"\"成功! " );
      }, function(e){
      outLine( "分享到\""+s.description+"\"失败: "+e.code+" - "+e.message );
      } );
      }
      /**
  • 解除所有分享服务的授权
    */
    function cancelAuth(){try{
    outSet( "解除授权:" );
    for ( var i in shares ) {
    var s = shares[i];
    if ( s.authenticated ) {
    outLine( "取消\""+s.description+"\"");
    }
    s.forbid();
    }
    // 取消授权后需要更新服务列表
    updateSerivces();
    outLine( "操作成功!" );}catch(e){alert(e);}
    }
    // 拍照添加图片分享
    function shareCameraPicture(){
    outSet("拍照添加分享图片:");
    var cmr=plus.camera.getCamera();
    cmr.captureImage(function(p){
    plus.io.resolveLocalFileSystemURL(p,function(entry){
    pic.src=entry.toLocalURL();
    pic.realUrl=p;
    outLine("拍照图片:"+pic.realUrl);
    },function(e){
    outLine("读取拍照文件错误:"+e.message);
    } );
    },function(e){
    outLine( "拍照失败:"+e.message );
    });
    }
    // 从相册添加图片分享
    function shareGalleryPicture(){
    outSet("从相册添加分享图片:");
    plus.gallery.pick(function(p){
    // 从相册返回的路径不需要转换可以直接使用
    pic.src=p;
    pic.realUrl=pic.src;
    outLine("选择图片:"+pic.realUrl);
    // plus.io.resolveLocalFileSystemURL(p,function(entry){
    // pic.src=entry.toLocalURL();
    // pic.realUrl=pic.src;
    // outLine("选择图片:"+pic.realUrl);
    // },function(e){
    // outLine("读取拍照文件错误:"+e.message);
    // } );
    });
    }
    // 使用Logo图片分享
    function shareLogoPicture(){
    outSet("使用Logo分享图片:");
    var url="_www/logo.png";
    plus.io.resolveLocalFileSystemURL(url,function(entry){
    pic.src=entry.toLocalURL();
    pic.realUrl=url;
    },function(e){
    outLine("读取Logo文件错误:"+e.message);
    } );
    }
    // 打开分享
    function shareShow(){
    bhref=false;
    wxbd985f6ec3fd4e99.style.display="block";
    // tencentweibo.style.display="block";
    popover.style.display="block";
    menu.style.display="block";
    setTimeout(function(){
    popover.style.opacity="1";
    menu.style.opacity="1";
    menu.style.webkitTransform="translateY(0)";
    },0);
    }
    // 分析链接
    function shareHref(){
    bhref=true;
    wxbd985f6ec3fd4e99.style.display="none";
    // tencentweibo.style.display="none";
    popover.style.display="block";
    menu.style.display="block";
    setTimeout(function(){
    popover.style.opacity="1";
    menu.style.opacity="1";
    menu.style.webkitTransform="translateY(0)";
    },0);
    }
    // 取消分享
    function shareHide(){
    setTimeout(function(){
    popover.style.display="none";
    menu.style.display="none";
    },500);
    popover.style.opacity="0";
    menu.style.opacity="0";
    menu.style.webkitTransform="translateY(100%)";
    }
    // 关闭分享(无动画)
    function shareClose(){
    popover.style.display="none";
    menu.style.display="none";
    popover.style.opacity="0";
    menu.style.opacity="0";
    menu.style.webkitTransform="translateY(100%)";
    }
    </script>
    <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
    <style type="text/css">

    sharecontent{

    width:80%;
    -webkit-user-select:text;
    border: 1px solid #6C6C6C;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    }

    pic{

    width:100px;
    height:100px;
    /border: 1px dashed #CCCCCC;/
    }
    .sharehref{
    width:80%;
    -webkit-user-select:text;
    border: 1px solid #6C6C6C;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    margin-bottom: .5em;
    }
    .popover{
    display:none;
    position:fixed;
    width:100%;
    height:100%;
    top:0;
    text-align: center;
    background-color: rgba(0,0,0,0.8);
    overflow: hidden;
    opacity:0;
    -webkit-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
    z-index:99998;
    }
    .menu{
    display:none;
    position:fixed;
    left:1%;
    width:98%;
    background: #FFF;
    bottom:1px;
    border-radius: 2px;
    opacity:0;
    -webkit-transform:translateY(100%);
    -webkit-transition: all 0.3s ease-in;
    transition: all 0.3s ease-in;
    z-index:99999;
    }
    </style>
    </head>
    <body>
    <header>
    <div class="nvbt iback" onclick="back(true);"></div>
    <div class="nvtt">Share</div>
    <div class="nvbt idoc" onclick="openDoc('Share Document','/doc/share.html')"></div>
    </header>
    <div id="dcontent" class="dcontent">
    <br/>
    <p class="heading">分享内容:</p>
    <textarea id="sharecontent" rows="3">我正在使用HBuilder+HTML5开发移动应用,赶紧跟我一起来体验!</textarea>
    <!--<br/><br/>
    <p class="heading">分享图片:</p>
    <table style="width:100%;">
    <tbody>
    <tr>
    <td style="width:30%"><div class="button button-select" onclick="shareCameraPicture()">拍照</div></td>
    <td style="width:30%"><div class="button button-select" onclick="shareGalleryPicture()">相册选取</div></td>
    <td style="width:30%"><div class="button button-select" onclick="shareLogoPicture()">使用logo图</div></td>
    </tr>
    </tbody>
    </table>
    <img id="pic" src="../img/add.png"/>
    <br/>-->
    <div class="button" onclick="shareShow()">分 享</div>
    <div style="padding: 0.5em 1em;"><hr color="#EEE"/></div>
    <p class="heading">链接地址:</p>
    <input id="sharehref" class="sharehref" type="url" value="http://www.dcloud.io/" placeholder="请输入要分享的链接地址"/>
    <p class="heading">链接标题:</p>
    <input id="sharehrefTitle" class="sharehref" type="text" value="DCloud HBuilder-做最好的HTML5开发工具" placeholder="请输入要分享的链接标题"/>
    <p class="heading">链接描述:</p>
    <input id="sharehrefDes" class="sharehref" type="text" value="我正在使用HBuilder+HTML5开发移动应用,赶紧跟我一起来体验!" placeholder="请输入要分享的链接描述"/>
    <div class="button" onclick="shareHref()">分享链接</div>
    <br/><br/>
    <div style="padding: 0.5em 1em;"><hr color="#EEE"/></div>
    <p class="des">如果需要解除分享中绑定的用户信息,请点击解除授权:</p>
    <div class="button" onclick="cancelAuth()">解除授权</div>
    </div>
    <div id="output">
    Share模块管理客户端的社交分享功能,提供调用终端社交软件的分享能力。通过plus.share可获取社交分享管理对象。
    </div>
    <div id="popover" class="popover"></div>
    <div id="menu" class="menu">
    <div id="wxbd985f6ec3fd4e99" class="button" onclick="shareAction('AAAAAAA','BBBBBBBB');">发送给微信好友</div>
    <div class="button button-waring" onclick="shareHide()">取 消</div>
    </div>
    </body>
    </html>

2015-02-12 11:29 负责人:无 分享
已邀请:
炸鸡排超人

炸鸡排超人

你发一大串谁看啊

该问题目前已经被锁定, 无法添加新回复