以下是源码
var log = document.createElement('div');
log.setAttribute('id', 'log');
document.body.appendChild(log);
var logger = {
i: function(info) {
add(info, 'i');
},
e: function(err) {
add(err, 'e');
}
};
function add(msg, level) {
var row = document.createElement('div');
row.setAttribute('class', 'log-row log-' + level);
row.innerHTML = msg;
document.querySelector('#log').appendChild(row);
}
var config = {"url":"http://saas.eduto.com/User/index.php/Home/Login/dingDingIsvLogin?corpid=ding3fd3e80d89b9034435c2f4657eb6378f","nonceStr":1460,"agentId":"50407135","timeStamp":1479533426,"corpId":"ding3fd3e80d89b9034435c2f4657eb6378f","suite_key":"suitezawadsugvy0xgkwq","signature":"7262d63f9a449577c7d417e0c29892d767f31b2c"};
dd.config({
agentId:config.agentId,
corpId: config.corpId,
timeStamp: config.timeStamp,
nonceStr: config.nonceStr,
signature: config.signature,
jsApiList: [
'runtime.info',
'device.notification.prompt',
'biz.chat.pickConversation',
'device.notification.confirm',
'device.notification.alert',
'device.notification.prompt',
'biz.chat.open',
'biz.util.open',
'biz.user.get',
'biz.contact.choose',
'biz.telephone.call',
'biz.util.uploadImage',
'biz.ding.post']
});
dd.userid=0;
dd.ready(function() {
logger.i('dd.ready rocks!');
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: _config.corpId, //企业id
onSuccess: function (info) {
logger.i('authcode: ' + info.code);
$.ajax({
url: '/sendMsg.php',
type:"POST",
data: {"event":"get_userinfo","code":info.code,"corpId":_config.corpId},
dataType:'json',
timeout: 900,
success: function (data, status, xhr) {
var info = JSON.parse(data);
if (info.errcode === 0) {
logger.i('user id: ' + info.userid);
dd.userid = info.userid;
}
else {
logger.e('auth error: ' + data);
}
},
error: function (xhr, errorType, error) {
logger.e(errorType + ', ' + error);
}
});
},
onFail: function (err) {
logger.e('requestAuthCode fail: ' + JSON.stringify(err));
}
});
$('.chooseonebtn').on('click', function() {
dd.biz.chat.pickConversation({
corpId: _config.corpId, //企业id
isConfirm:'false', //是否弹出确认窗口,默认为true
onSuccess: function (data) {
var chatinfo = data;
if(chatinfo){
console.log(chatinfo.cid);
dd.device.notification.prompt({
message: "发送消息",
title: chatinfo.title,
buttonLabels: ['发送', '取消'],
onSuccess : function(result) {
var text = result.value;
if(text==''){
return false;
}
$.ajax({
url: '/sendMsg.php',
type:"POST",
data: {"event":"send_to_conversation","cid":chatinfo.cid,"sender":dd.userid,"content":text,"corpId":_config.corpId},
dataType:'json',
timeout: 900,
success: function (data, status, xhr) {
var info = data;
logger.i('sendMsg: ' + JSON.stringify(data));
if(info.errcode==0){
logger.i('sendMsg: 发送成功');
/**
* 跳转到对话界面
*/
dd.biz.chat.open({
cid:chatinfo.cid,
onSuccess : function(result) {
},
onFail : function(err) {}
});
}else{
logger.e('sendMsg: 发送失败'+info.errmsg);
}
},
error: function (xhr, errorType, error) {
logger.e(errorType + ', ' + error);
}
});
},
onFail : function(err) {}
});
}
},
onFail: function (err) {
}
});
});
$('.phonecall').on('click', function() {
dd.biz.contact.choose({
startWithDepartmentId: 0, //-1表示打开的通讯录从自己所在部门开始展示, 0表示从企业最上层开始,(其他数字表示从该部门开始:暂时不支持)
multiple: false, //是否多选: true多选 false单选; 默认true
users: [], //默认选中的用户列表,userid;成功回调中应包含该信息
corpId: _config.corpId, //企业id
max: 10, //人数限制,当multiple为true才生效,可选范围1-1500
onSuccess: function(data) {
if(data&&data.length>0){
var selectUserId = data[0].emplId;
if(selectUserId>0){
dd.biz.telephone.call({
users: [selectUserId], //用户列表,工号
corpId: _config.corpId, //企业id
onSuccess : function(info) {
logger.i('biz.telephone.call: info' + JSON.stringify(info));
},
onFail : function(err) {
logger.e('biz.telephone.call: error' + JSON.stringify(err));
}
})
}else{
return false;
}
}else{
return false;
}
},
onFail : function(err) {}
});
});
});
dd.error(function(err) {
logger.e('dd error: ' + JSON.stringify(err));
});
直接走error报错:dd error:{"message":"权限校验失败 Code:0-Message:","errorCode":3}是在没找出原因
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。