Android 如何通过xamarin移动应用程序添加save to phone google按钮和支付通行证
我已经成功创建了支持ASP.Net内核的Google支付通行证,我的rest api成功返回JWT令牌。我使用了save to phone web按钮,使用了JWT,效果很好,但我需要将Pass与我的Xamarin表单应用程序集成,在xamrin中,我如何添加save to phone按钮以及如何将JWT与该按钮绑定?最后,我找到了解决方案。如果您的后端服务器为您的google pay pass返回JWT,您可以通过依赖服务在Xamarin表单中实现这一点 如果您可以使用JWT链接和意图、JWT POST请求方法和本机Android SDK。请参考这个 我的通行证类型是忠诚卡,所以,我使用了 在将pass与应用程序集成之前,您可以使用chrome浏览器测试JWT。请用你的jwt在chrome浏览器中点击这个({jwt_generated})url,如果jwt正常,你将在浏览器中看到通行证 达到Android 如何通过xamarin移动应用程序添加save to phone google按钮和支付通行证,android,xamarin,xamarin.forms,google-pay,Android,Xamarin,Xamarin.forms,Google Pay,我已经成功创建了支持ASP.Net内核的Google支付通行证,我的rest api成功返回JWT令牌。我使用了save to phone web按钮,使用了JWT,效果很好,但我需要将Pass与我的Xamarin表单应用程序集成,在xamrin中,我如何添加save to phone按钮以及如何将JWT与该按钮绑定?最后,我找到了解决方案。如果您的后端服务器为您的google pay pass返回JWT,您可以通过依赖服务在Xamarin表单中实现这一点 如果您可以使用JWT链接和意图、JWT
namespace App.DependencyServices
{
public interface IGPayPass
{
void LoadGPayPass(string JWT);
}
}
public class GPayImplementation : IGPayPass
{
/// <summary>
/// summary:
/// This methode load the google pay pass from the JWT and open the pay passes in Google pay app
/// To show the pass in google pay we have to create an ACTION_VIEW
/// If pass is the loyality pass we can use the JWT link and intent method(https://developers.google.com/pay/passes/guides/get-started/implementing-the-api/save-to-google-pay#use-jwt-link-and-intent)
/// To load the pass send the https request to google pass class object like https://pay.google.com/gp/v/save/{jwt_generated}
///
/// parameters:
/// JWT : The server return this token for pay passes and pass via dependency service to this native implementation
///
/// returns:
///
/// </summary>
/// <param name="JWT"></param>
public void LoadGPayPass(string JWT)
{
//create context
Context context = Android.App.Application.Context;
string url = "https://pay.google.com/gp/v/save/" + JWT;
//Send the https request to google pay pass class object via Android intent
Intent intent = new Intent(Intent.ActionView, Uri.Parse(url));
//Assign new task Flag for intent otherwise runtime exepption will return
intent.AddFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
}
}
公共类GPayImplementation:IGPayPass
{
///
///总结:
///此方法从JWT加载谷歌支付通行证,并在谷歌支付应用程序中打开支付通行证
///要在google pay中显示通行证,我们必须创建一个ACTION\u视图
///如果pass是忠诚pass,我们可以使用JWT链接和意图方法(https://developers.google.com/pay/passes/guides/get-started/implementing-the-api/save-to-google-pay#use-jwt链接和意图)
///要加载pass,请将https请求发送到GooglePass类对象,如https://pay.google.com/gp/v/save/{jwt_生成的}
///
///参数:
///JWT:服务器将支付通行证和通过依赖关系服务传递的令牌返回到此本机实现
///
///返回:
///
///
///
公共无效LoadGPayPass(字符串JWT)
{
//创建上下文
Context Context=Android.App.Application.Context;
字符串url=”https://pay.google.com/gp/v/save/“+JWT;
//通过Android intent向google pay pass类对象发送https请求
Intent Intent=newintent(Intent.ActionView,Uri.Parse(url));
//为意图分配新任务标志,否则运行时验证将返回
intent.AddFlags(ActivityFlags.NewTask);
背景。开始触觉(意图);
}
}
if (response.HttpCode == HttpStatusCode.OK)
{
ResponseSting = response.Results.ToString();
//Remove quates from the JWT string
MembershipCardAndroidJWT = ResponseSting.TrimStart('"').TrimEnd('"');
//Pass The JWT string via dependency service to the Anroid native Environment
DependencyService.Get<IGPayPass>().LoadGPayPass(MembershipCardAndroidJWT);
}
if(response.HttpCode==HttpStatusCode.OK)
{
ResponseSting=response.Results.ToString();
//从JWT字符串中删除四分之一
MembershipCardRoidJwt=ResponseSting.TrimStart(“”).trimsend(““”);
//通过依赖项服务将JWT字符串传递给Anroid本机环境
DependencyService.Get().LoadGPayPass(MembershipCardAndroidJWT);
}
您能分享一下如何生成通行证吗?我特别关注“受信任的用户”和“课堂复习状态”