ionic4支付宝支付

要在app中进行支付宝支付的话,首先需要在支付宝开发平台注册账户,然后创建应用。创建完成应用后要注意配置签名。应用审核通过后我们就可以使用cordova支付宝支付插件完成支付。下面我们一起看看

1、 Ionic 支付宝支付之前的准备工作

1、百度搜索《支付宝开放平台》,或者点击下面链接进入支付宝开发接入页面: https://open.alipay.com/developmentAccess/developmentAccess.htm

2、点击支付应用 如下图创建应用





3、创建完成应用后设置应用公钥,然后提交审核。

详细教程参考https://www.itying.com/goods-1067.html


2、 Ionic 支付宝支付安装插件 完成支付


1.准备已有的ionic项目
2.找到插件地址

https://github.com/hhjjj1010/cordova-plugin-alipay-v2


3.Ionic支付宝支付插件 在线安装

cordova plugin add cordova-plugin-alipay-v2 --variable APP_ID=[your AppId]

cordova plugin add https://github.com/hhjjj1010/cordova-plugin-alipay-v2.git --variable APP_ID=[your AppId]

Ionic支付宝支付插件本地安装
1.下载插件到本地
2.cordova plugin add  插件路由 --variable APP_ID=[your AppId]

注意:在线安装需要电脑上面先安装 git,如果已经安装过git可以忽略


4.客户端调用服务器端接口生成订单签名信息,调用支付插件完成支付 完整代码如下:


import { Component } from '@angular/core';

import axios from 'axios';
declare let cordova;

@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})
export class Tab2Page {

  public url: string = 'http://agent.itying.com/alipay/index.php';   //服务器端接口
  constructor() {}
  doAlipay(){   
    axios.get(this.url)
    .then((response:any)=>{
      // handle success
      console.log(response.data);    
      this.doPayAction(response.data);
    })
    .catch((error)=> {
      // handle error
      console.log(error);
    });  

  }

  doPayAction(payParamsStr){
    cordova.plugins.alipay.payment(payParamsStr, (success) => {      
      console.log(success);      
     
    }, (error) => {     
      console.log(error);      
    }); 

  }
}



详细Ionic4支付宝支付教程参考https://www.itying.com/goods-1067.html