gpt4 book ai didi

ionic-framework - 如何在 Ionic 3 中集成 PayUMoney Gate 方式?

转载 作者:行者123 更新时间:2023-12-04 07:13:00 25 4
gpt4 key购买 nike

实际上,我需要用 Ionic 3 实现 PayUMoney。我知道,我没有合适的插件。但是我需要将 PayUMoney 处理与我的服务器集成并将确认发送到 ionic 3。请指导我解决这个问题。

最佳答案

我不确定您是否已经找到了解决方案,但这可能会帮助其他人寻找答案。

因此让我们假设您拥有所有必需的发布参数(您要么以某种方式在本地拥有它,要么从您的服务器获取它)。

this.paymentString = `
<html>
<body>
<form action="${this.post_url}" method="post" id="payu_form">
<input type="hidden" name="firstname" value="${this.firstname}"/>
<input type="hidden" name="email" value="${this.email}"/>
<input type="hidden" name="phone" value="${this.phone}"/>
<input type="hidden" name="surl" value="${this.surl}"/>
<input type="hidden" name="curl" value="${this.curl}"/>
<input type="hidden" name="furl" value="${this.furl}"/>
<input type="hidden" name="key" value="${this.key}"/>
<input type="hidden" name="hash" value="${this.hash}"/>
<input type="hidden" name="txnid" value="${this.txnid}"/>
<input type="hidden" name="productinfo" value="${this.productinfo}"/>
<input type="hidden" name="amount" value="${this.amount}"/>
<input type="hidden" name="service_provider" value="${this.service_provider}"/>
<button type="submit" value="submit" #submitBtn></button>
</form>
<script type="text/javascript">document.getElementById("payu_form").submit();</script>
</body>
</html>`;

console.log(this.paymentString);
this.paymentString = 'data:text/html;base64,' + btoa(paymentString);

所以基本上现在您有一个 base64 html 字符串,您可以将其传递给您的 InAppBrowser(来自 ionic native)。

请从 ionic native docs 找到如何在您的项目中包含 InAppBrowser (PS:也将 InAppBrowser 包含在 app.modules.ts 中)。

constructor(private iab: InAppBrowser) { }

下一步是在 AppBrowser 中打开您的 base64String 并监听交易是否完成。

const browser = this.iab.create(payString, "_self", {
location: 'no',
clearcache: 'yes',
hardwareback: 'no',
});
browser.on('loadstart').subscribe((event: InAppBrowserEvent) => {
if (event.url === this.surl) {
this.paymentSuccess();
} else if (event.url === this.furl) {
this.paymentFailure();
}
});

您在 paymentSuccess 和 paymentFailure 函数中做什么由您决定。

就是这样,应该按要求工作。


如果您打算在“productinfo”中发送 json 数据,请进一步阅读

您需要将其转换为 html 安全字符。

所以替换这一行

<input type="hidden" name="productinfo" value="${this.productinfo}"/>

<input type="hidden" name="productinfo" value="${this.htmlEntities(this.productinfo)}"/>

并具有将json数据转换为html安全字符的功能,

private htmlEntities(str) {
return String(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}

关于ionic-framework - 如何在 Ionic 3 中集成 PayUMoney Gate 方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47474135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com