122 lines
5.2 KiB
Java
122 lines
5.2 KiB
Java
package com.xuebiping.bolizhuzi.utils;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
|
|
import com.fengliyan.device.DeviceManager;
|
|
import com.xuebiping.bolizhuzi.BuildConfig;
|
|
import com.xuebiping.bolizhuzi.controller.constant.Constant;
|
|
import com.xuebiping.bolizhuzi.view.base.PayWebViewActivity;
|
|
import com.fengliyan.uikit.toast.MaleToast;
|
|
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
|
|
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
|
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
|
import java.util.List;
|
|
|
|
public class PayUtils {
|
|
|
|
/**
|
|
* 汇付微信小程序支付
|
|
*
|
|
* @param context
|
|
* @param goodsID
|
|
* @param type
|
|
* @param mini_program_type 0-正式版 1-开发版 2-体验版
|
|
*/
|
|
public static void wxminiPay(Activity context, int goodsID, int type, String ghOriId, int mini_program_type) {
|
|
String appId = Constant.WECHAT_APP_ID; // 填应用AppId
|
|
IWXAPI api = WXAPIFactory.createWXAPI(context, appId);
|
|
boolean isWXAppInstalledAndSupported = api.isWXAppInstalled();
|
|
if (isWXAppInstalledAndSupported) {
|
|
api.openWXApp();
|
|
api.registerApp(appId);
|
|
String path = String.format("pages/info/index?token=%s&source_app=4&channel=wechat&goodsId=%d&type=%d&version=%s&source_id=%d", DeviceManager.getInstance().getToken(), goodsID, type, BuildConfig.VERSION_NAME, 1);
|
|
WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
|
|
// req.userName = "gh_302cef1cd1e8"; // 填小程序原始id
|
|
req.userName = ghOriId; // 填小程序原始id
|
|
req.path = path; //拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
|
|
if (mini_program_type == 2) {
|
|
req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;// 可选打开 开发版,体验版和正式版
|
|
} else if (mini_program_type == 1) {
|
|
req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_TEST;// 可选打开 开发版,体验版和正式版
|
|
} else {
|
|
req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版,体验版和正式版
|
|
}
|
|
api.sendReq(req);
|
|
} else {
|
|
MaleToast.showMessage(context, "未安装微信,不能支付");
|
|
}
|
|
}
|
|
|
|
//汇付支付宝唤醒
|
|
public static void ailWeb(String qrcodeUrl, Activity context) {
|
|
// 固定前缀
|
|
String topic = "alipays://platformapi/startapp?saId=10000007&qrcode=";
|
|
// 从汇付正扫接口获取的参数(以下值仅为示例)
|
|
String jumpUrl = topic + qrcodeUrl;
|
|
// 按以上示例拼接得出结果
|
|
// jumpUrl 为 alipays://platformapi/startapp?saId=10000007&qrcode=https://qr.alipay.com/bax02911brluc2xieoph6001
|
|
|
|
Intent intent = new Intent();
|
|
intent.setAction("android.intent.action.VIEW");
|
|
// jumpUrl 为先前示例中拼装的 url
|
|
Uri contentUrl = Uri.parse(jumpUrl);
|
|
intent.setData(contentUrl);
|
|
context.startActivity(intent);
|
|
}
|
|
|
|
/**
|
|
* 商福通支付
|
|
*
|
|
* @param context
|
|
* @param url
|
|
*/
|
|
public static void SFTPay(Activity context, String url) {
|
|
if (url.startsWith("weixin://")) {
|
|
IWXAPI api = WXAPIFactory.createWXAPI(context, null);
|
|
api.registerApp(Constant.WECHAT_APP_ID);
|
|
if (isWeChatAppInstalled(context, api)) {
|
|
Intent intent = new Intent();
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
intent.setData(Uri.parse(url));
|
|
context.startActivity(intent);
|
|
} else {
|
|
MaleToast.showMessage(context, "您还未安装微信客户端");
|
|
}
|
|
} else if (url.startsWith("https://")) {
|
|
Intent intent = new Intent(context, PayWebViewActivity.class);
|
|
intent.putExtra("ClickUrl", url);
|
|
intent.putExtra("type", 5);
|
|
context.startActivity(intent);
|
|
}
|
|
}
|
|
|
|
public static boolean isWeChatAppInstalled(Context context, IWXAPI api) {
|
|
if (api.isWXAppInstalled()) {
|
|
return true;
|
|
} else {
|
|
final PackageManager packageManager = context.getPackageManager();// 获取packagemanager
|
|
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
|
|
if (pinfo != null) {
|
|
for (int i = 0; i < pinfo.size(); i++) {
|
|
String pn = pinfo.get(i).packageName;
|
|
if (pn.equalsIgnoreCase("com.tencent.mm")) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static boolean parseScheme(String url) {
|
|
return url.contains("platformapi/startapp") || (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) && (url.contains("platformapi") && url.contains("startapp"));
|
|
}
|
|
}
|