# uni.getProvider(options)

获取服务供应商

# 参数

名称 类型 必填 默认值 描述
options GetProviderOptions -
名称 类型 必备 默认值 描述
service "oauth" | "share" | "payment" | "push" | "location" - 服务类型,可取值“oauth”、“share”、“payment”、“push”、“location”
- oauth: 授权登录
- share: 分享
- payment: 支付
- push: 推送
- location: 定位
success (result: GetProviderSuccess) => void | null - 接口调用成功的回调
fail (result: UniError) => void | null - 接口调用失败的回调函数
complete (result: any) => void | null - 接口调用结束的回调函数(调用成功、失败都会执行)
# GetProviderSuccess 的属性值
名称 类型 必备 默认值 描述
service "oauth" | "share" | "payment" | "push" | "location" - 服务类型
- oauth: 授权登录
- share: 分享
- payment: 支付
- push: 推送
- location: 定位
provider Array<string> - 得到的服务供应商
errMsg string - 描述信息

# getProvider 兼容性

Android iOS web
4.11 x 4.05

# 参见

相关 Bug

# 示例

hello uni-app x

<template>
 <!-- #ifdef APP -->
 <scroll-view class="page-scroll-view">
 <!-- #endif -->
   <view class="page">
     <page-head :title="title"></page-head>
     <view class="service-item" v-for="(item, index) in serviceList" :key="index">
       <text class="service-name">{{item.name}}:</text>
       <view class="provider-list">
         <text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2">{{item2}}</text>
       </view>
     </view>
     <button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
   </view>
 <!-- #ifdef APP -->
 </scroll-view>
 <!-- #endif -->
</template>

<script>
 type ProviderItem = {
   service : string,
   name : string,
   provider : string[]
 }

 export default {
   data() {
     return {
       title: 'provider',
       serviceList: [
         { service: "oauth", name: "登陆", provider: [] },
         { service: "share", name: "分享", provider: [] },
         { service: "payment", name: "支付", provider: [] },
         { service: "push", name: "推送", provider: [] },
         { service: "location", name: "定位", provider: [] }
       ] as ProviderItem[]
     }
   },
   methods: {
     getProvider() {
       this.serviceList.forEach((item : ProviderItem) => {
         uni.getProvider({
           service: item.service,
           success: (e) => {
             this.updateProvider(e.service, e.provider);
           }
         })
       })
     },
     updateProvider(service : string, provider : string[]) {
       const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
         return item.service == service
       });
       if (item != null) {
         item.provider = provider
       }
     }
   }
 }
</script>

<style>
 .page {
   padding: 15px;
 }

 .service-item {
   margin-top: 10px;
 }

 .service-name {
   font-weight: bold;
 }

 .provider-list {
   margin-left: 32px;
 }

 .provider-item {
   line-height: 1.5;
 }

 .btn-get-provider {
   margin-top: 30px;
 }
</style>

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 描述
errMsg string - 错误信息