**支付宝学生认证流程 **
1、对接 支付宝 开发 添加权限
2、使用原生开发
项目根目录添加 ---
---mycomponents
- student-verify
- index.axml
- index.js
- index.json
index.axml
<view>
<slot></slot>
<student-verify shopName="{{shopName}}" shopLink="{{shopLink}}" shopLogo="{{shopLogo}}" ref="onStudentVerifyRef" onSuccess="onSuccess" />
</view>
index.js
// const plugin = requirePlugin("myPlugin");
Component({
props: { isVerify: false },
options: {
// 使用基础库内置的数据变化观测器
observers: true,
},
data() {
return {
shopLink: `alipays://platformapi/startapp?appId=${process.env.APP_ID}&page=${encodeURIComponent(
"/pages/index/index"
)}`,
shopName: "XXXX小程序",
shopLogo:
"xxxx.jpg",
};
},
didMount() {
this.$page.childverifyRef = this;
},
methods: {
// 绑定 ref
onStudentVerifyRef(ref) {
console.log("ref>>>>>>>>>", ref);
this.studentVerifyRef = ref;
},
onSuccess() {
console.log("认证成功回调 :>> ");
},
// 商户⾃定义的触发事件,触发校验
async onVerify() {
const verifyInfo = await this.studentVerifyRef.verify();
console.log("verifyInfo :>> ", verifyInfo);
if (verifyInfo && verifyInfo.success) {
if (
verifyInfo.status == "passed" &&
verifyInfo.studentInfo.collegeOnlineTag == 1
) {
this.$page.data.verifySuccess && this.$page.data.verifySuccess(verifyInfo); //学生认证通过
} else {
this.$page.data.verifyFail && this.$page.data.verifyFail();
}
} else this.$page.data && this.$page.data.verifyFail();
},
},
});
index.json
{
"usingComponents": {
"student-verify": "plugin://studentVerifyPlugin/student-verify"
}
}
pages.json
{
"path": "",
"style": {
"navigationBarTitleText": "",
// #ifdef MP-ALIPAY
,"usingComponents": {
"custom-student-verify": "/mycomponents/student-verify/index"
}
// #endif
}
}
调用方式
<template>
<!-- 学生认证 -->
<!-- #ifdef MP-ALIPAY -->
<custom-student-verify></custom-student-verify>
<!-- #endif -->
</template>
methods:{
// 学生认证
verify(){
// #ifdef MP-ALIPAY
this.$scope.childverifyRef.onVerify()
// #endif
// #ifdef MP-WEIXIN
// #endif
},
verifySuccess(data){
console.log('认证成功 :>> ', data);
this.handleConfirm();
},
verifyFail(){
console.log('认证失败 :>> ');
},
}