注意:因 API 不断添加和更新,请调用Api的同学,联系bennyzqliu进行记录,方便以后接口升级和调整时方便告知。
.sendPayRequest(json, callback)
@since4.4.0 根据预支付ID直接调起微信支付
参数:
{JSONString} json 支付所需Json数据, 格式如下:
{
//腾讯新闻分配的业务ID, 示例为10001
"qnbid": "10001",
//公众平台账户的AppId,此处AppId需要与partnerId绑定
"appid": "wx073f4a4daff0abe8",
//分配的财付通商户号
"partnerid": "1217628601",
//预支付ID
"prepayid": "11010000001408054f82907e84946a52",
//随机字符串
"noncestr": "a8849b052492b5106526b2331e526138",
//时间戳
"timestamp": "1407233000",
//生成预支付ID时生成
"package": "Sign=WXPay",
//签名
"sign": "d35ec7242bac16907fcbf52c630e077fdfb3ceb9"
}
{String} callback 支付后客户端返回回调函数。
示例:
(function(window, document) {
window["sendPayRequestCallBack"] = function(Json) {
alert("支付后:" + Json);
};
var jsonObject = {
"qnbid" : "10001",
"appid" : "wx073f4a4daff0abe8",
"partnerid" : "1217628601",
"prepayid" : "11010000001408054f82907e84946a52",
"noncestr" : "a8849b052492b5106526b2331e526138",
"timestamp" : "1407233000",
"package" : "Sign=WXPay",
"sign" : "d35ec7242bac16907fcbf52c630e077fdfb3ceb9"
};
var element = document.querySelector("#SendPayRequest a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.sendPayRequest) {
window.TencentNews.sendPayRequest(JSON.stringify(jsonObject), "sendPayRequestCallBack");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
调起微信支付
.showNativeLoginWithType (type, callback, callbackParam)
@since4.4.0 调起用户登录界面
参数:
{String} type 登录框显示类型:"all",“qqorweixin”,"qq","weixin","sina"。
{String} callback 登录后回调函数。
{String} callbackParam 需传递给回调函数的自定义参数。
示例:
(function(window, document) {
window["showNativeLoginWithTypeCallBack"] = function(status, params) {
if(status == 1) {
alert("登录成功:" + params);
}
if(status == 0) {
alert("登录失败:" + params);
}
};
var elementA = document.querySelector("#ShowNativeLoginWithType .all");
elementA.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.showNativeLoginWithType) {
window.TencentNews.showNativeLoginWithType("all", "showNativeLoginWithTypeCallBack", "自定义参数");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
.isQQLogin(callback)
@since4.4.0判断手机QQ是否登录
参数:
{String} callback 回调函数。
示例:
(function(window, document) {
window["isQQLoginCallback"] = function(isLogin) {
if(isLogin == 1) {
alert("已登录");
}
if(isLogin == 0) {
alert("未登录");
}
};
var element = document.querySelector("#IsQQLogin a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.isQQLogin) {
alert(window.TencentNews.isQQLogin("isQQLoginCallback"));
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
点我
.isWeixinLogin(callback)
@since4.4.0判断微信是否登录
参数:
{String} callback 回调函数。
示例:
(function(window, document) {
window["isWeixinLoginCallback"] = function(isLogin) {
if(isLogin == 1) {
alert("已登录");
}
if(isLogin == 0) {
alert("未登录");
}
};
var element = document.querySelector("#IsWeixinLogin a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.isWeixinLogin) {
alert(window.TencentNews.isWeixinLogin("isWeixinLoginCallback"));
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
点我
.copy(str)
复制文字, 将传入的字符复制到粘贴板
参数:
{String} str 要复制的文本
示例:
(function(window, document) {
var element = document.querySelector("#Copy a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.copy) {
window.TencentNews.copy("test");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
点我
.checkCanOpenNativeUrl(url, callback, callbackParam)
检测本机是否安装了某应用
参数:
{String} packName 包名
{String} callBack 回调函数
{String} callbackParam 需传递给回调函数的自定义参数。
示例:
(function(window, document) {
window["checkCanOpenNativeUrlCallBack"] = function(url, result, userInfo) {
alert("url : " + url +", result : " + result + ", userInfo : " + userInfo);
};
var element = document.querySelector("#CheckCanOpenNativeUrl a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.checkCanOpenNativeUrl) {
alert(window.TencentNews.checkCanOpenNativeUrl("tenvideo2://", "checkCanOpenNativeUrlCallBack", "自定义参数"));
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
点我
.openNativeUrl(url, callback, callbackParam)
打开或下载应用, 通过包名打开本地应用或传入下载链接调浏览器下载
参数:
{String} packName 包名或下载链接
{String} callBack 回调函数
{String} callbackParam 需传递给回调函数的自定义参数。
示例:
(function(window, document) {
window["openNativeUrlCallBack"] = function(url, success, userInfo) {
alert("url : " + url +", success : " + success + ", userInfo : " + userInfo);
};
var elementA = document.querySelector("#OpenNativeUrl .open");
elementA.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.openNativeUrl) {
window.TencentNews.openNativeUrl("tenvideo2://", "openNativeUrlCallBack", "自定义参数");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
打开本地应用
.showTip(text, type)
@since4.4.0 弹出提示框
参数:
{String} text 提示文本信息
{String} type 提示表情,"0":无,"1":对勾,"2":悲伤,"3":叹号,"4":生气
示例:
//弹出提示框
(function(window, document) {
var elementC = document.querySelector("#ShowTip .Sorrow");
elementC.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.showTip) {
window.TencentNews.showTip("这是悲伤提示", "2");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
.showAlert(type, title, text, btns, callback, userInfo)
@since4.4.0 弹出提示框,含按钮
参数:
{String} type 预留类型字段,统一设成"0"
{String} title 提示title信息
{String} text 提示文本信息
{String} btns 数组格式字符串,为空或者无效时按钮使用"确定"默认值
{String} callback 回调函数
{String} userInfo 需传递给回调函数的自定义参数
示例:
(function(window, document) {
window["showAlertCallBack"] = function(clickBtnName, userInfo) {
alert("clickBtnName : " + clickBtnName +", userInfo : " + userInfo);
};
var element = document.querySelector("#ShowAlert a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.showAlert) {
window.TencentNews.showAlert("0", "腾讯新闻", "警告提示", JSON.stringify(["确定", "取消"]), "showAlertCallBack", "自定义参数");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
.getNetworkStatus(callback)
@since4.4.0 获取网络状态
参数:
{String} callback 回调函数
示例:
(function(window, document) {
window["getNetworkStatusCallBack"] = function(status) {
alert("status : " + status);
};
var element = document.querySelector("#GetNetworkStatus a");
element.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.getNetworkStatus) {
window.TencentNews.getNetworkStatus("getNetworkStatusCallBack");
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
.startMicBlowListen(micBlowStartCallBack, micBlowEndCallBack, micBlowVolumeCallBack)
.stopMicBlowListen()
@since4.4.0 吹一吹
参数:
{String} micBlowStartCallBack 吹一吹开始回调
{String} micBlowStartCallBack 吹一吹结束回调
{String} micBlowStartCallBack 吹一吹的力度回调
示例:
(function(window, document) {
var mm_micBlowLog = "";
window["micBlowStartCallBack"] = function() {
mm_micBlowLog = mm_micBlowLog + "micBlowStartCallBack\n";
};
window["micBlowEndCallBack"] = function() {
mm_micBlowLog = mm_micBlowLog + "micBlowEndCallBack\n";
};
window["micBlowVolumeCallBack"] = function(volume) {
alert("volume : " + volume);
mm_micBlowLog = mm_micBlowLog + "micBlowVolumeCallBack(volume : " + volume + ")\n";
};
var elementA = document.querySelector("#MicBlow a.start");
elementA.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.startMicBlowListen) {
window.TencentNews.startMicBlowListen("micBlowStartCallBack", "micBlowEndCallBack", "micBlowVolumeCallBack");
} else {
alert("没有注册接口!");
}
}, false);
var elementB = document.querySelector("#MicBlow a.stop");
elementB.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.stopMicBlowListen) {
window.TencentNews.stopMicBlowListen();
alert(mm_micBlowLog);
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
.setGestureQuit(flag)
@since4.4.0 开启或禁用手势右划退出功能
参数:
{Boolean} packName true禁止手势右划退出,false开启手势右划退出
示例:
(function(window, document) {
var elementA = document.querySelector("#SetGestureQuit a.disable-gesture");
elementA.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.setGestureQuit) {
window.TencentNews.setGestureQuit(false);
} else {
alert("没有注册接口!");
}
}, false);
var elementB = document.querySelector("#SetGestureQuit a.enable-gesture");
elementB.addEventListener("click", function() {
if (window.TencentNews && window.TencentNews.setGestureQuit) {
window.TencentNews.setGestureQuit(true);
} else {
alert("没有注册接口!");
}
}, false);
}(this, this.document));
模块化显示页面片
业务接入,请先申请qnbid,申请成功后会自动生成如下配置代码与异步加载JS代码.
var QN_CONFIG = {
/**
* {qnbid} 分配的业务ID, 示例为10001
* {elementId} 需要显示内容的页面元素
* {linkurl} 页面片显示所需js地址
* {tag} 文章内容Tag
*/
"10001": {
"elementId": "QNTICKET0",
"linkurl": "http://www.qq.com/d.js",
"qnbid": "10001",
"tag": ["all", "英超", "德甲"]
}
};
setTimeout(function() {
Q.loadJsFile("http://www.qq.com/d.js", function(success, linkUrl) {
d.init();
});
}, 100);