开发者社区> 问答> 正文

关于dd.runtime.permission.requestAuthCode不执行问题

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>


<!DOCTYPE html>


<script src="http://g.alicdn.com/ilw/ding/0.7.5/scripts/dingtalk.js"></script>
     <script   >
  
      


         function  general1()
         {
            
              //alert('asdasd');
             dd.config({agentId:'<%=RtHashtable()["agentId"]%>',
                 corpId:'<%=RtHashtable()["corpId"]%>',
                 timeStamp:<%=RtHashtable()["timeStamp"]%>,
                 nonceStr:'<%=RtHashtable()["nonceStr"]%>',
                 signature:'<%=RtHashtable()["signature"]%>',
                 jsApiList:['runtime.info',
                 'biz.contact.choose',
                 'device.notification.confirm',
                 'device.notification.alert',
                 'device.notification.prompt',
                 'biz.ding.post',
             'runtime.permission.requestAuthCode',
             'device.geolocation.get',
             'biz.ding.post',
             'biz.contact.complexChoose']});


            //  alert('asdasd11');
             //获取免登授权码 -- 注销获取免登服务,可以测试jsapi的一些方法
            // dd.ready(function ()
             {
                 dd.runtime.permission.requestAuthCode({
                     corpId:'<%=RtHashtable()["corpId"]%>',
                     onSuccess: function (result) {
                         //alert(JSON.stringify(result));
                         document.cookie="code="+ result["code"];
                         location.href="WebForm2.aspx?code=" + result["code"];
                        
                        // alert(JSON.stringify(result));
                     },
                     onFail: function (err) { alert(JSON.stringify(err));}


                 });
             }
            // )
             ;


         }


        </script>
    <script>
        function general(){  
            alert('hello javascript!');  
            window.location='WebForm2.aspx';
            }  


    </script>






  







<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body  >


    <form id="form1" runat="server">
<script  defer="defer">
    alert('hello javascript!');
    window.onload=  general1();
</script>


        <button onclick="general1()" style="height: 140px; width: 396px">点击这里</button>
         <div>
    
    </div>
    


      
    </form>


  
</body>
</html>




<script  defer="defer">
    alert('hello javascript!');
    window.onload=  general1();
</script>



dd.runtime.permission.requestAuthCode  不执行

<button onclick="general1()"     dd.runtime.permission.requestAuthCode    正常
是什么原因?




展开
收起
dalin1998 2016-03-27 20:41:01 17257 0
5 条回答
写回答
取消 提交回答
  • 感谢您的建议,由此给您带来的不便请谅解
    2016-03-29 09:41:04
    赞同 展开评论 打赏
  • Re关于dd.runtime.permission.requestAuthCode不执行问题
    第一段里  
    // dd.ready(function ()
    你把他注释了怎么运行


    第二段你把dd.config套到dd.ready里用真是神来之笔。。。。。

    dd.config();
    dd.ready();
    dd.error();

    这三个是平级的

    dd.runtime.permission.requestAuthCode要么套在dd.ready()里用,要么确保dd.ready()已经成功完成之后再用
    2016-03-28 10:51:36
    赞同 展开评论 打赏
  • 1. 请在dd.ready同目录下,加上dd.error.
    2. try-catch,确保js没有语法错误。
    2016-03-27 22:17:57
    赞同 展开评论 打赏
  • Re关于dd.runtime.permission.requestAuthCode不执行问题
    不是的,dd.error 也没有触发 ,现在代码是  页面加载完毕 window.onload 调用 general1() 函数 dd.runtime.permission.requestAuthCode    不执行  ,页面显示完毕  点击 button  调用 general1() 函数 dd.runtime.permission.requestAuthCode 正常执行  


    在前面引用 dd.ready 后 两种情况  dd.runtime.permission.requestAuthCode   都不执行  

    -------------------------

    Re关于dd.runtime.permission.requestAuthCode不执行问题
    好像 页面没有显示完毕  dd.runtime.permission.requestAuthCode   不能执行  有什么解决方法?

    -------------------------

    Re关于dd.runtime.permission.requestAuthCode不执行问题
    <script type="text/javascript" >
        
    //循环执行,每隔3秒钟执行一次showalert()
    window.setInterval(showalert, 1300);
    function showalert()
    {
      
        var btn = document.getElementById("btn1");
        //通用方法
        btn.click();
    }


    </script>


    页面 延时 执行 也正常

    -------------------------

    Re关于dd.runtime.permission.requestAuthCode不执行问题
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>


    <!DOCTYPE html>


    <script src="http://g.alicdn.com/ilw/ding/0.7.5/scripts/dingtalk.js"></script>
         <script  type="text/javascript" >
      
          


             function  general1()
             {
                 dd.ready(function() {
                     try
                     {
                         //alert('asdasd');
                         dd.config({agentId:'<%=RtHashtable()["agentId"]%>',
                             corpId:'<%=RtHashtable()["corpId"]%>',
                             timeStamp:<%=RtHashtable()["timeStamp"]%>,
                             nonceStr:'<%=RtHashtable()["nonceStr"]%>',
                             signature:'<%=RtHashtable()["signature"]%>',
                             jsApiList:['runtime.info',
                             'biz.contact.choose',
                             'device.notification.confirm',
                             'device.notification.alert',
                             'device.notification.prompt',
                             'biz.ding.post',
                         'runtime.permission.requestAuthCode',
                         'device.geolocation.get',
                         'biz.ding.post',
                         'biz.contact.complexChoose']});


                         //  alert('asdasd11');
                         //获取免登授权码 -- 注销获取免登服务,可以测试jsapi的一些方法
                         // dd.ready(function ()
                         {
                             dd.runtime.permission.requestAuthCode({
                                 corpId:'<%=RtHashtable()["corpId"]%>',
                                 onSuccess: function (result) {
                                     //alert(JSON.stringify(result));
                                     document.cookie="code="+ result["code"];
                                     location.href="WebForm2.aspx?code=" + result["code"];
                            
                                     // alert(JSON.stringify(result));
                                 },
                                 onFail: function (err) { alert(JSON.stringify(err));}


                             });
                         }
                         // )
                         ;


                         dd.error(function(err) {
                             logger.e('dd error: ' + JSON.stringify(err));
                             alert('asdasd11111');
                         });
                     }
                     catch(e)
                     {
                         alert('asdasd11111');


                     }
                 })


                 dd.error(function(err) {
                     alert('asdasd11111');
                     logger.e('dd error: ' + JSON.stringify(err));
                 });






             }
            
            </script>



    <script type="text/javascript" >
        
    //循环执行,每隔3秒钟执行一次showalert()
      //  var t1 = window.setInterval(showalert, 2000);
        window.setTimeout(showalert, 1000);
      
    function showalert()
    {
      
        var btn = document.getElementById("btn1");
        //通用方法
        btn.click();


        


    }












    </script>






      







    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body  >


        <form id="form1" runat="server">



            <button id="btn1" onclick="general1()" style="height: 140px; width: 396px">点击这里</button>
        
        


          
        </form>


      
    </body>
    </html>




    已加   还是不行  如何延后 执行 小于2 秒 就不正常

    -------------------------

    Re关于dd.runtime.permission.requestAuthCode不执行问题
    上面代码修改成
    function  general1()
             {
                
                 try{
                     //alert('asdasd');
                     dd.config({agentId:'<%=RtHashtable()["agentId"]%>',
                         corpId:'<%=RtHashtable()["corpId"]%>',
                         timeStamp:<%=RtHashtable()["timeStamp"]%>,
                         nonceStr:'<%=RtHashtable()["nonceStr"]%>',
                         signature:'<%=RtHashtable()["signature"]%>',
                         jsApiList:['runtime.info',
                         'biz.contact.choose',
                         'device.notification.confirm',
                         'device.notification.alert',
                         'device.notification.prompt',
                         'biz.ding.post',
                     'runtime.permission.requestAuthCode',
                     'device.geolocation.get',
                     'biz.ding.post',
                     'biz.contact.complexChoose']});


                     //  alert('asdasd11');
                     //获取免登授权码 -- 注销获取免登服务,可以测试jsapi的一些方法
                     dd.ready(function ()
                     {


                         dd.runtime.info({
                             onSuccess: function(info) {
                                 logger.i('runtime info: ' + JSON.stringify(info));
                
                             },
                             onFail: function(err) {
                                 logger.e('fail: ' + JSON.stringify(err));
                             }
                         });
        
                         dd.runtime.permission.requestAuthCode({
                             corpId:'<%=RtHashtable()["corpId"]%>',
                             onSuccess: function (result) {
                                 //alert(JSON.stringify(result));
                                 document.cookie="code="+ result["code"];
                                 location.href="WebForm2.aspx?code=" + result["code"];
                            
                                 // alert(JSON.stringify(result));
                             },
                             onFail: function (err) { alert(JSON.stringify(err));}


                         });
                     }
                     )
                     ;


                     dd.error(function(err) {
                         logger.e('dd error: ' + JSON.stringify(err));
                         alert('asdasd11111');
                     });
                 }
                 catch(e)
                 {


                 }
            }
            
            </script>


      dd.ready(function ()    嵌套  代码就部执行了  不清楚原因







    -------------------------

    Re关于dd.runtime.permission.requestAuthCode不执行问题
    问题解决了

    signature签名  生成错了  

        C# 按照以下代码生成      signature    
      string str1= "jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}";        
    str1= string.Format(string1, jsApiTicket, nonceStr, timestamp, url);

    string signature = FormsAuthentication.HashPasswordForStoringInConfigFile(str1, "SHA1").ToLower();


    建议钉钉 完善 文档  


    agentIdString微应用ID,普通企业可以通过OA后台的微应用-设置查看agentID,ISV需要通过调用授权成功后的get_auth_info获取授权方的agentid
    corpIdString企业ID
    timeStampString生成签名的时间戳
    nonceStrString生成签名的随机串
    signatureString签名
    jsApiListArray需要调用的jsapi列表





    签名 是 按照什么规律生成的

    2016-03-27 21:04:37
    赞同 展开评论 打赏
  • 是不是dd.ready的回调函数没触发?而是触发了dd.error?
    2016-03-27 20:45:04
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载