案例原始碼 ] 【分享】APICloud例項原始碼,乾貨!!
阿新 • • 發佈:2019-01-31
- //語音讀text裡面的文字
- var text=document.getElementById('ready').value;
- alert(text);
- var obj = api.require('speechRecognizer');
- obj.read({
- readStr:'緣'+text
- },function(ret,err) {
- if(ret.status) {
- ret.speakProgress
- }else{
- err.msg
- }
- });
- //QQ分享
- 在config裡面新增
- <feature name="qq">
- <param name="urlScheme" value="tencent101064640" />
- <param name="apiKey" value="101064640" />
- </feature>
- //分享新聞到QQ頁面JS
- function weichat(){
- //判斷是否安裝了QQ
- var obj = api.require('qq');
- obj.installed(function(ret,err){
- if(ret.status){
- //如果安裝了就登陸QQ
- var obj = api.require('qq');
- obj.login(function(ret,err){
- if(ret.status)
- {
- var obj = api.require('qq');
- obj.shareNews({
- url:'http://www.uzmap.com',
- title:'新聞分享',
- description:'新聞描述',
- imgUrl:'http://upload.wabei.cn/2011/0807/20110807025817844.jpg'
- });
- }else
- {
- alert("登入失敗");
- }
- });
- }else{
- api.alert({msg: "沒有安裝"});
- }
- });
- }
- //分享圖片到QQ
- function weichat(){
- //判斷是否安裝了QQ
- var obj = api.require('qq');
- obj.installed(function(ret,err){
- if(ret.status){
- //如果安裝了就登陸QQ
- var obj = api.require('qq');
- obj.login(function(ret,err){
- if(ret.status)
- {
- var obj = api.require('qq');
- obj.shareImage({
- title:'test',
- description:'testd',
- imgPath:'widget://icon/icon150x150.png'//圖片地址為APP目錄下的圖片
- },function(ret,err){
- alert(ret.status);
- if(ret.status)
- {
- alert(1);
- }else
- {
- api.alert({msg:err.msg});
- }
- });
- }else
- {
- alert("登入失敗");
- }
- });
- }else{
- api.alert({msg: "沒有安裝"});
- }
- });
- }
- //分享音樂
- function weichat(){
- //判斷是否安裝了QQ
- var obj = api.require('qq');
- obj.installed(function(ret,err){
- if(ret.status){
- //如果安裝了就登陸QQ
- var obj = api.require('qq');
- obj.login(function(ret,err){
- if(ret.status)
- {
- var obj = api.require('qq');
- obj.shareMusic({
- url:'http://play.baidu.com/?__m=mboxCtrl.playSong&__a=120125029&__o=song/120125029||playBtn&fr=altg8||www.baidu.com#',//音樂的地址
- title:'小蘋果',//音樂名字
- description:'小小蘋果',//音樂描述
- imgUrl:'http://musicdata.baidu.com/data2/pic/122112246/122112246.jpg', //音樂的圖片地址
- type:'QZone'//分享內容到好友或空間,取值範圍QZone,QFriend,可為空
- },function(ret,err){
- alert(ret.status);
- if(ret.status)
- {
- alert(1);
- }else
- {
- api.alert({msg:err.msg});
- }
- });
- }else
- {
- alert("登入失敗");
- }
- });
- }else{
- api.alert({msg: "沒有安裝"});
- }
- });
- }
- //分享視訊
- function weichat(){
- //判斷是否安裝了QQ
- var obj = api.require('qq');
- obj.installed(function(ret,err){
- if(ret.status){
- //如果安裝了就登陸QQ
- var obj = api.require('qq');
- obj.login(function(ret,err){
- if(ret.status)
- {
- var obj = api.require('qq');
- var obj = api.require('qq');
- obj.shareVideo({
- url:'http://www.iqiyi.com/w_19rs3ri1x9.html',
- title:'視訊',
- description:'王力巨集',
- imgUrl:'widget://icon/icon150x150.png'
- },function(ret,err){
- alert(ret.status);
- if(ret.status)
- {
- alert(1);
- }else
- {
- api.alert({msg:err.msg});
- }
- });
- }else
- {
- alert("登入失敗");
- }
- });
- }else{
- api.alert({msg: "沒有安裝"});
- }
- });
- }
- //分享到新浪微博
- function sinaWeiBo(){
- var sinaWeiBo = api.require('sinaWeiBo');
- sinaWeiBo.auth(function(ret,err){
- if (ret.status) {
- sinaWeiBo.sendRequest({
- contentType: 'text',
- text: '山不在高,有仙則名;水不在深,有龍則靈。',
- imageUrl: 'WeiShare://icon/icon150x150.png'
- },function(ret,err){
- if (ret.status) {
- api.alert({
- title: '發表微博',
- msg: '發表成功',
- buttons: ['確定']
- });
- }else{
- api.alert({
- title: '發表微博',
- msg: '發表失敗',
- buttons: ['確定']
- });
- };
- });
- }else{
- api.alert({msg:'授權失敗'+err.msg});
- }
- });
- }
- //開啟圖片瀏覽器
- function sinaWeiBo(){
- var obj = api.require('imageBrowser');
- obj.openImages({
- imageUrls: ['widget://icon/icon150x150.png','widget://launch/launch1080x1920.png'],
- showList:true,
- activeIndex:3
- });
- }
- //掃描信用卡
- function sinaWeiBo() {
- var obj = api.require('cardReader');
- obj.open(function(ret, err) {
- if (ret.status) {
- api.alert({
- msg : '卡號:' + ret.cardNum + '過期的月' + ret.expiryMonth + '過期的年' + ret.expiryYear + 'cvv號' + ret.cvv
- });
- } else {
- api.alert({
- msg : err.msg
- });
- }
- });
- }
- //獲取通訊錄的姓名與電話號碼
- function sinaWeiBo() {
- api.openContacts(
- function(ret,err){
- if(ret.status){
- var msg = '姓名:'+ret.name+'--電話:'+ret.phone;
- api.alert({msg:msg});
- }else{
- api.alert({msg:err.msg});
- };
- }
- );
- }
- //消失的提示框
- function show(){
- api.toast({
- msg: '網路錯誤',
- duration:2000,
- location: 'bottom'
- });
- }