my.chooseAlipayContact 是用于喚起支付寶通訊錄,選擇一個(gè)或者多個(gè)支付寶聯(lián)系人的 API。
// API-DEMO page/API/contact/contact.json
{
"defaultTitle": "Contact"
}
<!-- API-DEMO page/API/contact/contact.axml-->
<view class="page">
<view class="page-description">聯(lián)系人 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">選擇聯(lián)系人</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">手機(jī)號(hào)</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">支付寶賬號(hào)</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">微信號(hào)</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">聯(lián)系地址</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">網(wǎng)站</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">添加到手機(jī)聯(lián)系人</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',//僅包含雙向手機(jī)通訊錄聯(lián)系人,也即雙方手機(jī)通訊錄都存有對(duì)方號(hào)碼的聯(lián)系人
multiChooseMax: 3, // 最多能選擇三個(gè)聯(lián)系人
multiChooseMaxTips: '超過選擇的最大人數(shù)了',
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 | 否 | 單次最多選擇聯(lián)系人個(gè)數(shù),默認(rèn)值為 1,最大值為 10。 |
success | Function | 否 | 調(diào)用成功的回調(diào)函數(shù)。 |
fail | Function | 否 | 調(diào)用失敗的回調(diào)函數(shù)。 |
complete | Function | 否 | 調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)。 |
入?yún)?Object 類型,屬性如下:
屬性 | 類型 | 描述 |
---|---|---|
contacts | Object/Array | 選中的支付寶聯(lián)系人數(shù)組,數(shù)組內(nèi)部對(duì)象字段見下表。 |
屬性 | 類型 | 描述 |
---|---|---|
realName | String | 賬號(hào)的真實(shí)姓名。 |
mobile | String | 賬號(hào)對(duì)應(yīng)的手機(jī)號(hào)碼。 |
String | 賬號(hào)的郵箱。 | |
avatar | String | 賬號(hào)的頭像鏈接。 |
userId | String | 支付寶賬號(hào)唯一標(biāo)識(shí)符。 |
注意:返回的 mobile
和 email
字段不一定全部有值,取決于所選取聯(lián)系人的支付寶賬號(hào)類型是手機(jī)號(hào)還是郵箱。
錯(cuò)誤碼 | 描述 | 解決方案 |
---|---|---|
10 | 沒有權(quán)限。 | 檢查權(quán)限設(shè)置。 |
11 | 用戶取消操作(或設(shè)備未授權(quán)使用通訊錄)。 | 建議設(shè)備授權(quán)使用通訊錄。 |
my.chooseContact 是喚起選擇聯(lián)系人的 API,默認(rèn)只包含支付寶聯(lián)系人,可通過修改參數(shù)選擇手機(jī)通訊錄聯(lián)系人或者雙向通訊錄聯(lián)系人。
基礎(chǔ)庫 1.4.0 或更高版本;支付寶客戶端 10.1.8 或更高版本,若版本較低,建議采取 兼容處理。
// API-DEMO page/API/contact/contact.json
{
"defaultTitle": "Contact"
}
<!-- API-DEMO page/API/contact/contact.axml-->
<view class="page">
<view class="page-description">聯(lián)系人 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">選擇聯(lián)系人</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">手機(jī)號(hào)</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">支付寶賬號(hào)</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">微信號(hào)</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">聯(lián)系地址</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">網(wǎng)站</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">添加到手機(jī)聯(lián)系人</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',//僅包含雙向手機(jī)通訊錄聯(lián)系人,也即雙方手機(jī)通訊錄都存有對(duì)方號(hào)碼的聯(lián)系人
multiChooseMax: 3, // 最多能選擇三個(gè)聯(lián)系人
multiChooseMaxTips: '超過選擇的最大人數(shù)了',
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 類型,屬性如下:
屬性 | 類型 | 必填 | 描述 |
---|---|---|---|
chooseType | String | 是 | 選擇類型,值為 single(單選)或者 multi(多選)。 |
includeMobileContactMode | String | 否 | 選擇手機(jī)通訊錄聯(lián)系人的模式。none:默認(rèn)為只包含支付寶聯(lián)系人,不包含手機(jī)通訊錄聯(lián)系人;known:僅包含雙向通訊錄聯(lián)系人,即雙方手機(jī)通訊錄都存有對(duì)方號(hào)碼的聯(lián)系人;all:包含所有通訊錄聯(lián)系人。 |
includeMe | Boolean | 否 | 是否包含自己。 |
multiChooseMax | Number | 否 | 最大選擇人數(shù),僅 chooseType 為 multi 時(shí)才有效。 |
multiChooseMaxTips | String | 否 | 多選達(dá)到上限時(shí)提示的文案,僅 chooseType 為 multi 時(shí)才有效。 |
success | Function | 否 | 調(diào)用成功的回調(diào)函數(shù)。 |
fail | Function | 否 | 調(diào)用失敗的回調(diào)函數(shù)。 |
complete | Function | 否 | 調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)。 |
說明:當(dāng)用戶沒有選擇任何聯(lián)系人時(shí),返回也是 success,但是返回值為空。
入?yún)?Object 類型,屬性如下:
屬性 | 類型 | 描述 |
---|---|---|
contactsDicArray | StringArray | 選擇返回的用戶信息 |
屬性 | 類型 | 描述 |
---|---|---|
userId | String | 支付寶賬號(hào)唯一標(biāo)識(shí)符。 |
avatar | String | 賬號(hào)的頭像鏈接。 |
mobile | String | 賬號(hào)對(duì)應(yīng)的手機(jī)號(hào)碼。 |
realName | String | 賬號(hào)的真實(shí)姓名。 |
displayName | String | 賬號(hào)的顯示名稱,即支付寶設(shè)置的備注名稱,默認(rèn)為朋友圈里面的昵稱。 |
my.choosePhoneContact 是選擇本地系統(tǒng)通信錄中某個(gè)聯(lián)系人的電話的 API。
// API-DEMO page/API/contact/contact.json
{
"defaultTitle": "Contact"
}
<!-- API-DEMO page/API/contact/contact.axml-->
<view class="page">
<view class="page-description">聯(lián)系人 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">選擇聯(lián)系人</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">手機(jī)號(hào)</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">支付寶賬號(hào)</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">微信號(hào)</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">聯(lián)系地址</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">網(wǎng)站</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">添加到手機(jī)聯(lián)系人</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',//僅包含雙向手機(jī)通訊錄聯(lián)系人,也即雙方手機(jī)通訊錄都存有對(duì)方號(hào)碼的聯(lián)系人
multiChooseMax: 3, // 最多能選擇三個(gè)聯(lián)系人
multiChooseMaxTips: '超過選擇的最大人數(shù)了',
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 類型,屬性如下:
屬性 | 類型 | 必填 | 描述 |
---|---|---|---|
success | Function | 否 | 調(diào)用成功的回調(diào)函數(shù)。 |
fail | Function | 否 | 調(diào)用失敗的回調(diào)函數(shù)。 |
complete | Function | 否 | 調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)。 |
入?yún)?Object 類型,屬性如下:
屬性 | 類型 | 描述 |
---|---|---|
name | String | 選中的聯(lián)系人姓名。 |
mobile | String | 選中的聯(lián)系人手機(jī)號(hào)。 |
錯(cuò)誤碼 | 描述 | 解決方案 |
---|---|---|
10 | 沒有權(quán)限。 | 檢查權(quán)限限制。 |
11 | 用戶取消操作(或設(shè)備未授權(quán)使用通訊錄)。 | 建議設(shè)備授權(quán)使用通訊錄。 |
更多建議: