如何获取手机通讯录

如何获取手机通讯录

 1  1       var user_id = $api.getStorage('user_id');
 2  2 
 3  3       var contacts = api.require('contacts');
 4  4       // console.log(api.pageParam.carname);
 5  5       contacts.queryByPage({
 6  6           count: 200,
 7  7           pageIndex: 0
 8  8       }, function(ret, err) {
 9  9           if (ret) {
10 10 
11 11               var phonelist = ret.contacts;
12 12               var fullName;
13 13 
14 14               var sto = ret.contacts;
15 15               var arr = [];
16 16               sto.forEach(function(item) {
17 17                   arr.push({
18 18                       contact_name: item.fullName,
19 19                       contact_mobile: item.phones
20 20                   })
21 21               });
22 22               for (var i in arr) {
23 23                   var contact_mobile = arr[i]['contact_mobile'];
24 24                   var contact_mobile_new = new Array;
25 25                   for (var j in contact_mobile) {
26 26                       var maps = contact_mobile[j];
27 27                       for (var n in maps) {
28 28                           contact_mobile_new.push(maps[n]);
29 29                       }
30 30                   }
31 31                   arr[i]['contact_mobile'] = contact_mobile_new;
32 32               }
33 33           console.info(JSON.stringify(arr));
34 34 
35 35 //将通讯录传给后台
36 36           api.ajax({
37 37               url: 'http://xxxxxx/index/user/get_contact',
38 38               method: 'post',
39 39               data: {
40 40                   values: {
41 41                       user_id:user_id,
42 42                       contact:arr
43 43                   }
44 44               }
45 45           },function(ret, err){
46 46               if (ret) {
47 47                   alert( JSON.stringify( ret ) );
48 48               } else {
49 49                   alert( JSON.stringify( err ) );
50 50               }
51 51           });
52 52 
53 53             
54 54           } else {
55 55               alert(JSON.stringify(err));
56 56           }
57 57       });

 

转载于:https://www.cnblogs.com/zfdbk/p/10319222.html

你可能感兴趣的:(php,json,移动开发)