123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { NativeModules, NativeEventEmitter } from 'react-native'
- import * as authService from '../services/auth'
- import { ScaleUtil, accMul, accDiv } from '../utils/utils'
- import Toast from 'react-native-root-toast'
- let toast
- // 支付宝支付
- export const _AliPay = async (payment, payCallBack, payFailed, payGoback) => {
- /**
- * 1、生产支付单(需要模拟支付单数据) 返回支付单号
- * 2、以支付单号去支付
- * 3、订单信息去后台获取要支付的信息
- * 4、调起支付软件并支付
- * 5、将返回数据传后台进行验签
- * 6、验签后返回是否验签成功信息
- */
- if (toast) {
- Toast.hide(toast)
- }
- let totlal_result = ScaleUtil(payment.paymentAmount, 3)
- totlal_result = accDiv(Math.ceil(accMul(totlal_result, 100)), 100)
- const search = {
- subject: '渠道云助手在线支付',
- seller_id: '',
- out_trade_no: payment.paybillCode,
- total_amount: totlal_result,
- product_code: 'QUICK_MSECURITY_PAY',
- financialOrgId: payment.payeeId,
- // financialOrgId: "15cbaf47-e7dc-487b-97e1-96166314de55"
- }
- const pay = NativeModules.Alipay.pay
- const result = await authService.aliPay(search).catch(error => {
- toast = Toast.show('签名服务异常', { position: toastHeight })
- payFailed()
- console.log(error, 'error-Result!')
- })
- result.data = result.data.replace(/\+/g, ' ')
- let ret = await pay(result.data).catch(error => {
- toast = Toast.show('支付服务异常', { position: toastHeight })
- payFailed()
- })
- if (ret.resultStatus == '9000') {
- // 1-将返回的字符串传给后台验签
- // 在这写代码
- const returnSign = await authService
- .returnSign(JSON.parse(ret.result))
- .catch(() => {
- toast = Toast.show('验签服务异常', { position: toastHeight })
- payFailed()
- })
- if (returnSign && returnSign.data && returnSign.data == 'success') {
- payCallBack(ret)
- } else {
- toast = Toast.show('验签不通过,订单信息与发出不吻合', {
- position: toastHeight,
- })
- payFailed()
- }
- } else if (ret.resultStatus == '6001') {
- payGoback()
- } else {
- // 支付失败或取消
- payFailed()
- }
- }
- // 微信支付
- export const _WechatPay = async payment => {
- const Wxpay = NativeModules.Wxpay,
- //search = `body=${'渠道云销-支付'}&detail=${'测试数据'}&attach =${'附加数据--自定义'}&out_trade_no =${'商户订单号--统一支付单号'}&total_fee =${90}&spbill_create_ip =${'123.103.9.7'}&trade_type =${'APP'}`
- search = `body=${'易下单-支付'}&detail=${'测试数据'}&attach =${'附加数据--自定义'}&out_trade_no =${'商户订单号--统一支付单号'}&total_fee =${90}&spbill_create_ip =${'123.103.9.7'}&trade_type =${'APP'}`
- Wxpay.registerApp('wxdd9ee9be12443920') //注册微信
- const isSupported = await Wxpay.isSupported
- if (!isSupported) {
- toast = Toast.show('找不到微信应用,请安装最新版微信', {
- position: toastHeight,
- })
- return
- }
- const weChatAuth = await authService.weChatAuth(search)
- if (weChatAuth) {
- const unifiedOrder = await authService.unifiedOrder(weChatAuth)
- }
- // this.props.dispatch(
- // NavigationActions.navigate({ routeName: "ShoppingCartHomeTab" })
- // );
- // alert("微信支付");
- }
|