12、xamarin form中实现H5 网页唤醒微信支付的方法
在微信的支付中有种支付叫微信H5支付。方便用户在网页中轻松唤起微信进行支付。
当然微信不推荐大家使用这样的方式唤起微信支付。建议app还是使用正常的微信支付sdk即可
服务端与其他的建议参考微信支付官网进行适配我这里只讨论如何在xamarin forms 中嵌入Html5 实现支付
这里面有个问题就是如果没有安装微信app 是需要进行一些判断的
开始建立相关的代码
打开 MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:WeChatPayDemo"
x:Class="WeChatPayDemo.MainPage"> <StackLayout>
<WebView x:Name="wb" IsVisible="True" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> </WebView>
</StackLayout> </ContentPage>
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
} protected override void OnAppearing()
{
base.OnAppearing();
wb.Source = new UrlWebViewSource
{
Url = "http://wxpay.wxutil.com/mch/pay/h5.v2.php"
}; } }
然后安卓项目里面增加
WebRenderer.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.Android;
using AWebView = Android.Webkit.WebView;
[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(WeChatPayDemo.Droid.WebRenderer))]
namespace WeChatPayDemo.Droid
{
public class WebRenderer : ViewRenderer<Xamarin.Forms.WebView, AWebView>
{
Context _context; public WebRenderer(Context context) : base(context)
{
_context = context;
} protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e); if (Control == null)
{
var webView = new AWebView(_context);
webView.SetWebViewClient(new WebViewClient(_context));
webView.Settings.JavaScriptEnabled = true;
SetNativeControl(webView);
}
} protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Control != null && e.PropertyName == "Source")
{
var src = Element.Source as UrlWebViewSource;
Control.LoadUrl(src.Url);
}
}
} public class WebViewClient : Android.Webkit.WebViewClient
{
private Context _context;
public WebViewClient(Context context)
{
_context = context;
}
public override bool ShouldOverrideUrlLoading(AWebView view, IWebResourceRequest request)
{
if (request.Url.Scheme == "weixin")
{
Intent intent = new Intent() { };
intent.SetAction(Intent.ActionView);
intent.SetData(request.Url);
this._context.StartActivity(intent);
return true;
}
return base.ShouldOverrideUrlLoading(view, request);
} [Obsolete]
public override bool ShouldOverrideUrlLoading(AWebView view, string url)
{
if (url.StartsWith("weixin"))
{
Intent intent = new Intent() { };
intent.SetAction(Intent.ActionView);
intent.SetData(Android.Net.Uri.Parse(url));
this._context.StartActivity(intent);
return true;
}
return base.ShouldOverrideUrlLoading(view, url);
}
} }
在iOS里面增加
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using Foundation;
using UIKit;
using Xamarin.Forms.Platform.iOS;
[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(WeChatPayDemo.iOS.WebRenderer))]
namespace WeChatPayDemo.iOS
{
public class WebRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e); if (NativeView != null && e.NewElement != null)
SetupControlSettings(); } private void SetupControlSettings()
{
var webView = ((UIWebView)NativeView);
if (webView == null) return;
webView.Delegate = new CustomWebDelegate();
}
} public class CustomWebDelegate : UIWebViewDelegate
{ public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
if (request.Url.Scheme== "weixin")
{
UIApplication.SharedApplication.OpenUrl(request.Url);
}
return true;
} public override void LoadingFinished(UIWebView webView)
{ }
public override void LoadFailed(UIWebView webView, NSError error)
{ }
}
}
记得配置 iOS 的网络访问权限 和安卓的访问权限 至此 web里面唤起 微信支付完成
12、xamarin form中实现H5 网页唤醒微信支付的方法的更多相关文章
- 在Ubuntu 12.04系统中安装配置OpenCV 2.4.3的方法
在Ubuntu 12.04系统中安装配置OpenCV 2.4.3的方法 对于,在Linux系统下做图像识别,不像在windows下面我们可以利用Matlab中的图像工具箱来实现,我们必须借助Ope ...
- 前端如何在h5页面调用微信支付?
在微信服务号开发的时候经常会遇到微信支付的功能实现,通过实际经验自己总结了一下,前端在H5页面调起微信支付有两种办法,一是利用内置对象,二是通过引用微信的js sdk,亲测都能支付成功,从写法上来看用 ...
- 微信小程序web-view(webview) 嵌套H5页面 唤起微信支付的实现方案
场景:小程序页面有一个web-view组件,组件嵌套的H5页面,要唤起微信支付. 先讲一下我的项目,首先我是自己开发的一个H5触屏版的商城系统,里面含有购物车,订单支付等功能.然后刚开始,我们公众号里 ...
- H5网页唤醒app,判断app安装
在阅读本文之前你首先应该对js有基本对掌握,并且对Scheme,intent有一定的理解.更多的是代码 上午给朋友做了一个产品引导页,但是需要判断ios系统的TestFlight是否安装,进行了goo ...
- PHP中获取某个网页或文件内容的方法
1. 通过file_get_contents()函数$contents = file_get_contents('http://demo.com/index.php');echo $contents; ...
- h5网页在微信里打开 右上角分享到微信好友或者朋友圈
首先你需要一个分享接口地址,然后在自定义图片 标题 描述 如下: <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js& ...
- h5调起微信支付
后台需要进行生成签名获取参数. 前台代码: function onBridgeReady(appId,timeStamp,nonceStr,package1,paySign,signType,open ...
- 【微信H5支付】微信公众号里H5网页点击调取微信支付
最近在公众号里开发了下单支付H5网页,需要在H5里调用微信支付界面.开发思路和代码整理如下: todo...
- [5] 微信公众号开发 - 微信支付功能开发(网页JSAPI调用)
1.微信支付的流程 如下三张手机截图,我们在微信网页端看到的支付,表面上看到的是 "点击支付按钮 - 弹出支付框 - 支付成功后出现提示页面",实际上的核心处理过程是: 点击支付按 ...
随机推荐
- 2018.07.13 [HNOI2015]落忆枫音(容斥原理+dp)
洛谷的传送门 bzoj的传送门 题意简述:在DAG中增加一条有向边,然后询问新图中一共 有多少个不同的子图为"树形图". 解法:容斥原理+dp,先考虑没有环的情况,经过尝试不难发现 ...
- redis学习-有序集合(zset)常用命令
zadd:有序集合增加一个或者多个键值对 与set集合不同,zset添加的时候需要 指定 score,这个是用来排名的 zrange:返回指定范围的键 zcount:返回集合指定范围的个数(以每个键值 ...
- python编码(二)
谈谈Unicode编码,简要解释UCS.UTF.BMP.BOM等名词 问题一 使用Windows记事本的“另存为”,可以在GBK.Unicode.Unicode big endian和UTF-8这几种 ...
- 笔记:记录两个新接触的东东- required + placeholder
1.1 required="required" 1.2 placeholder 当用户还没有输入值时,输入型控件可能通过placeholder向用户显示描述性说明文字或者提示信息, ...
- Shell编程-06-Shell中的if语句
目录 基本语法 if示例 在任何一门语言中,判断语句总是少不了,今天来学习一下Shell中的if语句. 基本语法 单分支情况 第一种语法 if <条件表达式> then 语句 fi ...
- 配置使用sourcemap调试vue源码爬坑
环境: Google Chrome V72.0.3626.109 vue-dev V 2.6.10 爬坑的乐趣就不说了(我恨啊),以下说一下出坑要点 1. 在vue-dev的package.json ...
- DXDBGrid使用方法
http://www.cnblogs.com/gtsup/archive/2012/08/28/2660197.html dxDBGrid使用集锦 转载自:http://hi.baidu.com/ ...
- Eclipse使用Maven搭建Java Web项目,并直接部署Tomcat(转载)
原文地址:http://www.cnblogs.com/hackyo/p/6527910.html 1.环境: win10 Java 1.8 Maven 3.3.9 Eclipse IDE for J ...
- .net core Ocelot Consul 实现API网关 服务注册 服务发现 负载均衡
大神张善友 分享过一篇 <.NET Core 在腾讯财付通的企业级应用开发实践>里面就是用.net core 和 Ocelot搭建的可扩展的高性能Api网关. Ocelot(http:// ...
- Java中的String,StringBuilder,StringBuffer的区别
这三个类之间的区别主要是在两个方面,即运行速度和线程安全这两方面. 首先说运行速度,或者说是执行速度,在这方面运行速度快慢为:StringBuilder > StringBuffer > ...