admin
2021-05-13 4a8f1bec26519a25f073739534e653a4f7c9e11d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.tejia.lijin.app.util;
 
import android.app.Activity;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
 
import com.alibaba.baichuan.android.trade.model.AlibcShowParams;
import com.alibaba.baichuan.android.trade.model.OpenType;
import com.alibaba.baichuan.trade.biz.AlibcConstants;
import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams;
import com.wpc.library.util.common.StringUtils;
import com.wpc.library.util.security.DEScrypt;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.util.baichuan.AlibcTradeUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.util.HashMap;
import java.util.Map;
 
import static android.content.Context.MODE_PRIVATE;
 
/**
 * 淘宝订单解密和找回
 */
public class OrderTransformationLink {
 
    private Activity mContext;
    WebView webview;
    private AlibcShowParams alibcShowParams;//页面打开方式,默认,H5,Native
    private Map<String, String> exParams;//yhhpass参数
    AlibcTaokeParams alibcTaokeParams;
    private String orderJS;
    private String orderUrl;
    private String source;
 
    public OrderTransformationLink(Activity context, String orderJS, String orderUrl) {
        mContext = context;
        this.orderUrl = orderUrl;
        this.orderJS = DEScrypt.decode(orderJS, "WWVTaGlGQU5MSTg4OSor", "Kk0jMzRmPyw=");
        initView();
    }
 
    public OrderTransformationLink(Activity context, String orderJS, String orderUrl, String source) {
        this.source = source;
        mContext = context;
        this.orderUrl = orderUrl;
        if (!orderUrl.startsWith("http"))
            this.orderUrl = DEScrypt.decode(orderUrl, "WWVTaGlGQU5MSTg4OSor", "Kk0jMzRmPyw=");
        this.orderJS = DEScrypt.decode(orderJS, "WWVTaGlGQU5MSTg4OSor", "Kk0jMzRmPyw=");
        initView();
    }
 
 
    private void initView() {
        webview = new WebView(mContext);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setAppCacheEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setDatabaseEnabled(true);
        webSettings.setTextZoom(100);
        webview.setDrawingCacheEnabled(true);
        webview.setWebViewClient(mWebviewClient);
        webview.addJavascriptInterface(new JavaInterface(), "handle");
        alibcShowParams = new AlibcShowParams();
        alibcShowParams.setOpenType(OpenType.Auto);
        exParams = new HashMap<>();
        exParams.put(AlibcConstants.ISV_CODE, "appisvcode");
        exParams.put("alibaba", "阿里巴巴");//自定义参数部分,可任意增删
    }
 
    WebViewClient mWebviewClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
//            Log.e("mResult", url);
            if (url.contains("//h5.m.taobao.com/awp/core/detail.htm?")
                    || url.contains("//detail.m.tmall.com/item.htm?")
                    || url.contains("//item.taobao.com/item.htm?")) {
//                getTaoBaoLink(url);
            } else if (url.contains("/tbopen/") || url.startsWith("tbopen://")) {
                return true;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }
 
        @Override
        public void onPageFinished(WebView view, String url) {
            view.loadUrl("javascript:" + orderJS);
            super.onPageFinished(view, url);
        }
    };
 
 
    /**
     * 显示我的订单
     */
    public void showOrder() {
//        AlibcBasePage alibcBasePage = new AlibcPage(orderUrl);
//        AlibcTrade.show(mContext, webview, mWebviewClient, new WebChromeClient(), alibcBasePage,
//                alibcShowParams, alibcTaokeParams, null, new MiDuoTradeCallback(""));
//        AlibcTrade.openByUrl(mContext, "webOrder",
//                orderUrl, null, new WebViewClient(), new WebChromeClient(),
//                alibcShowParams, alibcTaokeParams, null, new MiDuoTradeCallback(""));
 
        AlibcTradeUtil.openByUrl(mContext,
                orderUrl, null, new WebViewClient(), new WebChromeClient(),
                alibcShowParams, alibcTaokeParams, null);
    }
 
 
    class JavaInterface {
        @JavascriptInterface
        public void showOrder(String ids) {
            String mIds = DEScrypt.encode(ids, "WWVTaGlGQU5MSTg4OSor", "Kk0jMzRmPyw=");
            String uid = mContext.getSharedPreferences("user", MODE_PRIVATE).getString("uid", "");
            if (StringUtils.isEmpty(source)) {
                ShoppingApi.uploadParsedOrder(mContext, uid, mIds, null);
            } else {
                ShoppingApi.uploadParsedOrder(mContext, uid, mIds, source, new BasicTextHttpResponseHandler() {
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        if (jsonObject.optInt("code") == 0) {
                            if (jsonObject.optString("msg").equals("")) {
                                mOnListener.onOrder("成功");
                            } else {
                                mOnListener.onOrder(jsonObject.optString("msg"));
                            }
                        } else {
                            if (jsonObject.optString("msg").equals("")) {
                                mOnListener.onOrder("失败");
                            } else {
                                mOnListener.onOrder(jsonObject.optString("msg"));
                            }
                        }
                    }
 
                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        super.onFailure(statusCode, headers, responseString, throwable);
                        mOnListener.onIOrderError("失败");
                    }
                });
            }
        }
    }
 
 
    //自定义公开接口,定义抽象方法
    public interface onListener {
        void onOrder(String reruen);
 
        void onIOrderError(String reruen);
    }
 
    //创建接口类型变量(接受传值并设置事件)
    private onListener mOnListener;
 
    //暴露设置接口的方法
    public void setOnOrderListener(onListener mOnListener) {
        this.mOnListener = mOnListener;
 
    }
}