123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- package com.yyrh.pay;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.webkit.DownloadListener;
- import android.webkit.WebChromeClient;
- import android.webkit.WebSettings;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import com.yyrh.constant.SDKSettings;
- import com.yyrh.ui.PageJsInteraction;
- import com.yyrh.sdk.YyrhSdkManager;
- import com.yyrh.ui.BaseDialog;
- import com.yyrh.utils.ResourceUtil;
- import com.yyrh.utils.TosUtil;
- import com.yyrh.utils.Utils;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.HashMap;
- import static com.yyrh.constant.SDKSettings.isLandscape;
- public class WvPayYyrhDialog extends BaseDialog implements View.OnClickListener{
- private Context context;
- private WebView webView;
- private WebSettings webSettings;
- private String url,orderId;
- private ImageView iv_reback_close;
- private HashMap<String, Object> payMap;
- public WvPayYyrhDialog(Context context) {
- super(context);
- this.context = context;
- }
- public WvPayYyrhDialog(Context context, int theme, String url, HashMap<String, Object> map) {
- super(context, theme);
- this.context = context;
- this.payMap = map;
- this.url = url;
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(ResourceUtil.getLayoutId(context,
- "qj_p_webview"));
- if (!isLandscape){
- LinearLayout ll_p_wb = findViewById(ResourceUtil.getId(context, "ll_p_wb"));
- Float x = Float.valueOf("0.9").floatValue();
- Float y = Float.valueOf("0.9").floatValue();
- ll_p_wb.setScaleX(x);
- ll_p_wb.setScaleY(y);
- }
- iv_reback_close = findViewById(ResourceUtil.getId(context,
- "iv_reback_close"));
- iv_reback_close.setOnClickListener(this);
- webView = findViewById(ResourceUtil.getId(context,
- "wb_with_xd"));
- webSettings = webView.getSettings();
- webSettings.setAllowFileAccess(true);
- webSettings.setJavaScriptEnabled(true);
- webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
- webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
- webSettings.setBuiltInZoomControls(false);// 设置支持缩放
- webSettings.setDomStorageEnabled(true);
- webView.addJavascriptInterface(new PageJsInteraction(this), "yyrhsdk");
- webView.setHorizontalScrollBarEnabled(false);//水平不显示
- webView.setVerticalScrollBarEnabled(false); //垂直不显示
- webView.setWebChromeClient(new WebChromeClient());
- webView.setWebViewClient(new WebViewClient(){
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- String httpHead = url.substring(0, 5);
- if (httpHead.equals("http:") || httpHead.equals("https")) {
- return super.shouldOverrideUrlLoading(view, url);
- } else if (url.equals("yyrhsdk://pay_close")) {
- dismiss();
- return true;
- } else if (url.equals("yyrhsdk://pay_success")) {
- dismiss();
- return true;
- } else {
- if (httpHead.equals("yyrhsdk")) {
- toDoHttp_https(url);
- return true;
- } else {
- openWXPay(url);
- return true;
- }
- }
- }
- @Override
- public void onPageFinished(WebView view, String url) {
- super.onPageFinished(view, url);
- }
- private void toDoHttp_https(String url) {
- String[] strArray = url.split("=");
- String strurl = Utils.decoBase64(strArray[1]);
- String code_url = null;
- try {
- JSONObject json = new JSONObject(strurl);
- code_url = json.getString("code_url");
- } catch (JSONException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- openWXPay(code_url);
- }
- private void openWXPay(String code_url) {
- try {
- Intent it = new Intent(Intent.ACTION_VIEW);
- it.setData(Uri.parse(code_url));
- context.startActivity(it);
- } catch (Exception e) {
- }
- }
- });
- webView.setDownloadListener(new DownloadListener() {
- @Override
- public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
- Uri uri = Uri.parse(url);
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- context.startActivity(intent);
- }
- });
- webView.loadUrl(url);
- }
- @Override
- public void onClick(View v) {
- int id = v.getId();
- if (id == ResourceUtil.getId(context, "iv_reback_close")) {
- dismiss();
- }
- }
- @Override
- public void dismiss() {
- super.dismiss();
- if (!Utils.judgeStrNull(orderId)){
- YyrhSdkManager.defaultManager(context).queryOrder(orderId,this.payMap);
- }
- }
- @Override
- public void zfOrder(String message) {
- super.zfOrder(message);
- orderId = message;
- }
- @Override
- public void zfColse() {
- super.zfColse();
- dismiss();
- }
- @Override
- public void showJsMsg(String message) {
- super.showJsMsg(message);
- new TosUtil(context,TosUtil.TOAST_ERROR, message).show();
- }
- }
|