微信小程序通信录

第一步:phone.wxml中

<view bindlongtap="clickPhone">{{phoneNum}}</view>

第二步:phone.json

{
  "navigationBarTitleText": "联系人"
}

第三步:phone.wxss

view{
  color:blue;
  padding: 15px;
  border-bottom: 1px solid gainsboro;
}

第四步:phone.js

Page({
  data: {
    phoneNum: '15966677700'
  },
  // 长按号码响应函数
  clickPhone: function () {
    var that = this;
    // 弹出操作菜单,提示是呼叫号码还是将号码添加到手机通讯录
    wx.showActionSheet({
      itemList: ['呼叫', '添加联系人'],
      success: function (res) {
        console.log("点击电话 res:", res)
        if (res.tapIndex === 0) { // 直接点击呼叫号码
            wx.makePhoneCall({
            phoneNumber: that.data.phoneNum,
            success: function (res_makephone) {
              console.log("呼叫电话返回:", res_makephone)
            }
          })
        } else if (res.tapIndex == 1) {          // 添加到手机通讯录
          wx.addPhoneContact({
            nickName:'alice',
            lastName: '刘',
            middleName:'晓明',
            firstName: '刘晓明',//姓名
            mobilePhoneNumber: that.data.phoneNum,//手机号
            success: function (res_addphone) {
              console.log("电话添加联系人返回:", res_addphone) //打印出添加的手机联系人信息              
                wx.showToast({title:'添加成功!'})
            }
          })
        }
      }
    })
  }
})

 

posted @ 2018-11-26 10:32  划边逅  阅读(651)  评论(0编辑  收藏  举报