Commit 34146f6f by 姜雷

添加app拉起支付页

parent 6b7ac716
import { ResponseDataEntity, baseFetch, customerFetch } from './index'; import { ResponseDataEntity, baseFetch, customerFetch } from "./index";
export type PayConfigParams = { export type PayConfigParams = {
areaId: number; areaId: number;
...@@ -28,14 +28,14 @@ type PayConfigResponse = { ...@@ -28,14 +28,14 @@ type PayConfigResponse = {
}; };
export const fetchPayConfig = ( export const fetchPayConfig = (
params: PayConfigParams, params: PayConfigParams
): Promise<ResponseDataEntity<PayConfigResponse>> => ): Promise<ResponseDataEntity<PayConfigResponse>> =>
baseFetch({ baseFetch({
url: '/dcxy/api/paymentAndActiveConf/getRechargeConf', url: "/dcxy/api/paymentAndActiveConf/getRechargeConf",
data: params, data: params
}); });
type RechargeOrderParams = { export type RechargeOrderParams = {
customerId: number; customerId: number;
id: number; id: number;
isFirstRecharge: number; isFirstRecharge: number;
...@@ -43,7 +43,7 @@ type RechargeOrderParams = { ...@@ -43,7 +43,7 @@ type RechargeOrderParams = {
}; };
export const rechargeOrder = ( export const rechargeOrder = (
params: RechargeOrderParams, params: RechargeOrderParams
): Promise<{ ): Promise<{
canCall: number; canCall: number;
code: number; code: number;
...@@ -52,9 +52,25 @@ export const rechargeOrder = ( ...@@ -52,9 +52,25 @@ export const rechargeOrder = (
payStr: string; payStr: string;
}> => }> =>
customerFetch({ customerFetch({
url: '/dcxy/app/rechargeOrder/rechargeOrder/smallProPay', url: "/dcxy/app/rechargeOrder/rechargeOrder/smallProPay",
method: 'POST', method: "POST",
data: { ...params, appId: 'wxf2cac8f84183c8fc' }, data: { ...params, appId: "wxf2cac8f84183c8fc" }
});
export const rechargeFromAppOrder = (
params: RechargeOrderParams & { token: string; clientIp: string }
): Promise<{
canCall: number;
code: number;
msg: string;
outTradeNo: string;
payStr: string;
}> =>
customerFetch({
url: "/dcxy/app/rechargeOrder/rechargeOrder/smallProPay",
method: "POST",
header: { token: params.token },
data: { ...params, appId: "wxf2cac8f84183c8fc" }
}); });
type CreditInfo = { type CreditInfo = {
...@@ -68,18 +84,16 @@ export const fetchCreditDeposites = (params: { ...@@ -68,18 +84,16 @@ export const fetchCreditDeposites = (params: {
areaId: number; areaId: number;
}): Promise<ResponseDataEntity<CreditInfo>> => }): Promise<ResponseDataEntity<CreditInfo>> =>
baseFetch({ baseFetch({
url: '/dcxy/api/creditDeposits', url: "/dcxy/api/creditDeposits",
data: params, data: params
}); });
export const fetchOperationMode = (params: { export const fetchOperationMode = (params: {
areaId: number; areaId: number;
}): Promise< }): Promise<ResponseDataEntity<{
ResponseDataEntity<{ mode: string;
mode: string; }>> =>
}>
> =>
baseFetch({ baseFetch({
url: '/dcxy/api/operationModeConf', url: "/dcxy/api/operationModeConf",
data: params, data: params
}); });
import Taro, { request } from '@tarojs/taro'; import Taro, { request } from "@tarojs/taro";
import store from '../store/index'; import store from "../store/index";
import { import {
BASE_SERVER_URL, BASE_SERVER_URL,
CUSTOMER_SERVER_URL, CUSTOMER_SERVER_URL,
...@@ -10,8 +10,8 @@ import { ...@@ -10,8 +10,8 @@ import {
SMPRO_URL, SMPRO_URL,
GX_URL, GX_URL,
APP_HOME_URL, APP_HOME_URL,
WSAHING_MACHINE_URL, WSAHING_MACHINE_URL
} from '../constants/index'; } from "../constants/index";
export type ResponseDataEntity<T> = { export type ResponseDataEntity<T> = {
code: number; code: number;
...@@ -33,12 +33,14 @@ const createFetch = (basePath: string) => { ...@@ -33,12 +33,14 @@ const createFetch = (basePath: string) => {
header: token header: token
? { ? {
token: token, token: token,
reqSource: 'wxmini', reqSource: "wxmini",
...entity.header
} }
: { : {
reqSource: 'wxmini', reqSource: "wxmini",
...entity.header
}, },
url: basePath + entity.url, url: basePath + entity.url
}).then( }).then(
({ data }: ResponseEntity): ResponseDataEntity<any> => { ({ data }: ResponseEntity): ResponseDataEntity<any> => {
if (data.code === SuccessCode) { if (data.code === SuccessCode) {
...@@ -46,16 +48,16 @@ const createFetch = (basePath: string) => { ...@@ -46,16 +48,16 @@ const createFetch = (basePath: string) => {
} }
if (data.code === LogoutCode) { if (data.code === LogoutCode) {
Taro.reLaunch({ Taro.reLaunch({
url: '/pages/Login/Login', url: "/pages/Login/Login"
}); });
throw data; throw data;
} }
Taro.showToast({ Taro.showToast({
title: data.msg || '网络错误', title: data.msg || "网络错误",
icon: 'none', icon: "none"
}); });
throw data; throw data;
}, }
); );
}; };
}; };
......
...@@ -45,6 +45,7 @@ class App extends Component { ...@@ -45,6 +45,7 @@ class App extends Component {
'pages/WashingMachine/WasherStart', 'pages/WashingMachine/WasherStart',
'pages/WashingMachine/AppointmentPay', 'pages/WashingMachine/AppointmentPay',
'pages/stringPay/stringPay', 'pages/stringPay/stringPay',
'pages/AppPay/AppPay',
], ],
window: { window: {
backgroundTextStyle: 'light', backgroundTextStyle: 'light',
......
import "./AppPay.scss";
import Taro, { Component, useState, useCallback } from "@tarojs/taro";
import { View, Button } from "@tarojs/components";
import { rechargeFromAppOrder } from "@/api/account";
import AES from "crypto-js/aes";
import Utf8 from "crypto-js/enc-utf8";
import ECBmode from "crypto-js/mode-ecb";
import PaddingPkcs7 from "crypto-js/pad-pkcs7";
import AppBackButton from "../../components/AppBackButton/AppBackButton";
class AppPay extends Component {
constructor(props) {
super(props);
this.state = {
showBack: false,
showError: false,
errorMsg: ""
};
}
componentWillMount() {
console.log("AppPayPathParams: ", this.$router.params);
const pathParams = this.$router.params;
const { clientIp, id, isFirstRecharge, customerId, token } = pathParams;
let entity = {
token,
clientIp,
id: Number(id),
isFirstRecharge: Number(isFirstRecharge),
customerId: Number(customerId),
rechargeType: "10"
};
// wx.showModal({
// content: JSON.stringify(entity)
// });
rechargeFromAppOrder(entity)
.then(res => {
const { payStr } = res;
console.log(res);
if (payStr) {
const payData = JSON.parse(payStr);
console.log(payData);
Taro.requestPayment({
timeStamp: payData.timeStamp.toString(),
nonceStr: payData.nonceStr,
package: payData.package,
signType: payData.signType,
paySign: payData.paySign
})
.then(res => {
console.log(res);
Taro.showToast({
title: "支付成功!",
icon: "success",
mask: true
});
this.setState({
showBack: true,
errorMsg: JSON.stringify({ code: 1, msg: res.errMsg })
});
})
.catch(err => {
Taro.showToast({
title: err.msg || "发起支付失败",
icon: "none"
});
this.setState({
showError: true,
errorMsg: JSON.stringify({ code: 0, msg: err.errMsg })
});
});
}
})
.catch(err => {
Taro.showToast({
title: err.msg || "呼起失败!",
icon: "none"
});
this.setState({
showError: true,
errorMsg: JSON.stringify({ code: 0, msg: err.msg })
});
});
}
goBackAppError() {
Taro.showModal({
title: "提示",
content: "呼起APP失败,请手动回到APP"
});
}
render() {
const { showBack, showError, errorMsg } = this.state;
return (
<View className="AppPay">
{showBack && (
<View className="AppPay-info">
支付成功
<Button
className="AppBackButton"
open-type="launchApp"
app-parameter={errorMsg}
onError={this.goBackAppError}
>
返回App
</Button>
</View>
)}
{showError && (
<View className="AppPay-info">
支付失败
<Button
className="AppBackButton"
open-type="launchApp"
app-parameter={errorMsg}
onError={this.goBackAppError}
>
返回App
</Button>
</View>
)}
</View>
);
}
}
export default AppPay;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment