• 下载
  • 社区

my.chooseAlipayContact

唤起支付宝通讯录,选择一个或者多个支付宝联系人。


扫码体验

联系人.jpeg


效果示例

联系人5-5.png


示例代码

// API-DEMO page/API/contact/contact.json
{
   "defaultTitle": "Contact"
}


<!-- API-DEMO page/API/contact/contact.axml-->
<view class="page">

  <view class="page-description">联系人 API</view>

  <view class="page-section">
    <view class="page-section-title">my.choosePhoneContact</view>
    <view class="page-section-demo">
      <button type="primary" onTap="choosePhoneContact">唤起本地通讯录</button>
    </view>
  </view>

  <view class="page-section">
    <view class="page-section-title">my.chooseAlipayContact</view>
    <view class="page-section-demo">
      <button type="primary" onTap="chooseAlipayContact">唤起支付宝通讯录</button>
    </view>
  </view>

  <view class="page-section">
    <view class="page-section-title">my.chooseContact</view>
    <view class="page-section-demo">
      <button type="primary" onTap="chooseContact">选择联系人</button>
    </view>
  </view>

  <view class="page-section">
    <view class="page-section-title">my.addPhoneContact</view>
    <view class="page-section-demo">

      <view style="font-size:18px;margin-top:18px;margin-bottom:18px">
        <text style="font-size:18px;margin-top:18px;margin-bottom:18px">基本信息</text>
      </view>

      <view class="form-row">
        <view class="form-row-label">昵称</view>
        <view class="form-row-content">
          <input id="nickName" onInput="onInput" class="input" value="七月流火" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">姓氏</view>
        <view class="form-row-content">
          <input id="lastName" onInput="onInput" class="input" value="Last" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">中间名</view>
        <view class="form-row-content">
          <input id="middleName" onInput="onInput" class="input" value="Middle" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">名字</view>
        <view class="form-row-content">
          <input id="firstName" onInput="onInput" class="input" value="First" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">备注</view>
        <view class="form-row-content">
          <input id="remark" onInput="onInput" class="input" value="这里是备注" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">手机号</view>
        <view class="form-row-content">
          <input id="mobilePhoneNumber" onInput="onInput" class="input" value="13800000000" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">支付宝账号</view>
        <view class="form-row-content">
          <input id="alipayAccount" onInput="onInput" class="input" value="alipay@alipay.com" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">微信号</view>
        <view class="form-row-content">
          <input id="weChatNumber" onInput="onInput" class="input" value="liuhuo" />
        </view>
      </view>

      <view style="font-size:18px;margin-top:18px;margin-bottom:18px">
        <text style="font-size:18px;margin-top:18px;margin-bottom:18px">联系地址</text>
      </view>

      <view class="form-row">
        <view class="form-row-label">国家</view>
        <view class="form-row-content">
          <input id="addressCountry" onInput="onInput" class="input" value="US" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">省份</view>
        <view class="form-row-content">
          <input id="addressState" onInput="onInput" class="input" value="California" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">城市</view>
        <view class="form-row-content">
          <input id="addressCity" onInput="onInput" class="input" value="San Francisco" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">街道</view>
        <view class="form-row-content">
          <input id="addressStreet" onInput="onInput" class="input" value="Mountain View" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">邮政编码</view>
        <view class="form-row-content">
          <input id="addressPostalCode" onInput="onInput" class="input" value="94016" />
        </view>
      </view>

      <view style="font-size:18px;margin-top:18px;margin-bottom:18px">
        <text style="font-size:18px;margin-top:18px;margin-bottom:18px">工作</text>
      </view>

      <view class="form-row">
        <view class="form-row-label">公司</view>
        <view class="form-row-content">
          <input id="organization" onInput="onInput" class="input" value="AntFin" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">职位</view>
        <view class="form-row-content">
          <input id="title" onInput="onInput" class="input" value="Developer" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">工作传真</view>
        <view class="form-row-content">
          <input id="workFaxNumber" onInput="onInput" class="input" value="11111111" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">工作电话</view>
        <view class="form-row-content">
          <input id="workPhoneNumber" onInput="onInput" class="input" value="11111112" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">公司电话</view>
        <view class="form-row-content">
          <input id="hostNumber" onInput="onInput" class="input" value="11111113" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">电子邮件</view>
        <view class="form-row-content">
          <input id="email" onInput="onInput" class="input" value="liuhuo01@sina.com" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">网站</view>
        <view class="form-row-content">
          <input id="url" onInput="onInput" class="input" value="www.alipay.com" />
        </view>
      </view>

      <view style="font-size:18px;margin-top:18px;margin-bottom:18px">
        <text style="font-size:18px;margin-top:18px;margin-bottom:18px">工作地址</text>
      </view>

      <view class="form-row">
        <view class="form-row-label">国家</view>
        <view class="form-row-content">
          <input id="workAddressCountry" onInput="onInput" class="input" value="China" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">省份</view>
        <view class="form-row-content">
          <input id="workAddressState" onInput="onInput" class="input" value="Zhejiang" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">城市</view>
        <view class="form-row-content">
          <input id="workAddressCity" onInput="onInput" class="input" value="Hangzhou" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">街道</view>
        <view class="form-row-content">
          <input id="workAddressStreet" onInput="onInput" class="input" value="Tianmushan Road" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">邮政编码</view>
        <view class="form-row-content">
          <input id="workAddressPostalCode" onInput="onInput" class="input" value="361005" />
        </view>
      </view>

      <view style="font-size:18px;margin-top:18px;margin-bottom:18px">
        <text style="font-size:18px;margin-top:18px;margin-bottom:18px">住宅</text>
      </view>

      <view class="form-row">
        <view class="form-row-label">传真</view>
        <view class="form-row-content">
          <input id="homeFaxNumber" onInput="onInput" class="input" value="11111114" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">电话</view>
        <view class="form-row-content">
          <input id="homePhoneNumber" onInput="onInput" class="input" value="11111115" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">国家</view>
        <view class="form-row-content">
          <input id="homeAddressCountry" onInput="onInput" class="input" value="Canada" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">省份</view>
        <view class="form-row-content">
          <input id="homeAddressState" onInput="onInput" class="input" value="Ontario" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">城市</view>
        <view class="form-row-content">
          <input id="homeAddressCity" onInput="onInput" class="input" value="Toronto" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">街道</view>
        <view class="form-row-content">
          <input id="homeAddressStreet" onInput="onInput" class="input" value="No.234 Road" />
        </view>
      </view>

      <view class="form-row">
        <view class="form-row-label">邮政编码</view>
        <view class="form-row-content">
          <input id="homeAddressPostalCode" onInput="onInput" class="input" value="123456" />
        </view>
      </view>

      <button type="primary" onTap="addPhoneContact">添加到手机联系人</button>

    </view>
  </view>

</view>


// API-DEMO page/API/contact/contact.js
Page({
  data:{
      "photoFilePath": "/sdcard/DCIM/Camera/a.jpg",
      "nickName": "七月流火",
      "lastName": "Last",
      "middleName": "Middle",
      "firstName": "First",
      "remark": "这里是备注",
      "mobilePhoneNumber": "13800000000",
      "homePhoneNumber": "11111115",
      "workPhoneNumber": "11111112",
      "homeFaxNumber": "11111114",
      "workFaxNumber": "11111111",
      "hostNumber": "11111113",
      "weChatNumber": "liuhuo",
      "alipayAccount": "alipay@alipay.com",
      "addressCountry": "US",
      "addressState": "California",
      "addressCity": "San Francisco",
      "addressStreet": "Mountain View",
      "addressPostalCode": "94016",
      "workAddressCountry": "China",
      "workAddressState": "Zhejiang",
      "workAddressCity": "Hangzhou",
      "workAddressStreet": "Tianmushan Road",
      "workAddressPostalCode": "361005",
      "homeAddressCountry": "Canada",
      "homeAddressState": "Ontairo",
      "homeAddressCity": "Toronto",
      "homeAddressStreet": "No.234 Road",
      "homeAddressPostalCode": "123456",
      "organization": "AntFin",
      "title": "Developer",
      "email": "liuhuo01@sina.com",
      "url": "www.alipay.com",
      success: (res) => {
        my.alert({
          content: 'addPhoneContact response: ' + JSON.stringify(res)
        });
      },
      fail: (res) => {
        my.alert({
          content: 'addPhoneContact response: ' + JSON.stringify(res)
        });
      }
  },
  choosePhoneContact() {
    my.choosePhoneContact({
      success: (res) => {
        my.alert({
          content: 'choosePhoneContact response: ' + JSON.stringify(res)
        });
      },
      fail: (res) => {
        my.alert({
          content: 'choosePhoneContact response: ' + JSON.stringify(res)
        });
      },
    });
  },
  chooseAlipayContact() {
    my.chooseAlipayContact({
      count: 2,
      success: (res) => {
        my.alert({
          content: 'chooseAlipayContact response: ' + JSON.stringify(res)
        });
      },
      fail: (res) => {
        my.alert({
          content: 'chooseAlipayContact response: ' + JSON.stringify(res)
        });
      },
    });
  },
  chooseContact() {
    my.chooseContact({
      chooseType: 'multi', // 多选模式
      includeMe: true,     // 包含自己
      includeMobileContactMode: 'known',//仅包含双向手机通讯录联系人,也即双方手机通讯录都存有对方号码的联系人
      multiChooseMax: 3,  // 最多能选择三个联系人
      multiChooseMaxTips: '超过选择的最大人数了',
      success: (res) => {
        my.alert({
          content: 'chooseContact : ' + JSON.stringify(res)
        });
      },
      fail: (res) => {
        my.alert({
          content: 'chooseContact : ' + JSON.stringify(res)
        });
      },
    });
  },
  onInput(e) {
    this.data[e.currentTarget.id] = e.detail.value;
  },
  addPhoneContact() {
    if (my.canIUse('addPhoneContact')) {
      my.addPhoneContact(this.data);
    } else {
      my.alert({ 
        title: '客户端版本过低',
        content: 'my.addPhoneContact() 需要 10.1.32 及以上版本'
      });
    }
  }
});


入参

Object 类型,属性如下:

属性

类型

必填

描述

count

Number

单次最多选择联系人个数,默认值为 1,最大值为 10。

success

Function

调用成功的回调函数。

fail

Function

调用失败的回调函数。

complete

Function

调用结束的回调函数(调用成功、失败都会执行)。


success 回调函数

入参为 Object 类型,属性如下:

属性

类型

描述

contacts

Object Array

选中的支付宝联系人数组,数组内部对象字段见下表。


contacts 返回字段说明

属性

类型

描述

realName

String

账号的真实姓名。

mobile

String

账号对应的手机号码。

email

String

账号的邮箱。

avatar

String

账号的头像链接。

userId

String

支付宝账号唯一标识符。

返回的 mobile email 字段不一定全部有值,取决于所选取联系人的支付宝账号类型是手机号还是邮箱。


结果码

结果码

描述

10

没有权限。

11

用户取消操作(或设备未授权使用通讯录)。