大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
package com.example.ex_example; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Handler; import android.os.Message; import android.util.Log; import com.unionpay.UPPayAssistEx; import com.unionpay.uppay.PayActivity; public class UnionPay implements Runnable{ // public static final int PLUGIN_VALID = 0; // public static final int PLUGIN_NOT_INSTALLED = -1; // public static final int PLUGIN_NEED_UPGRADE = 2; /***************************************************************** * mMode参数解释: "00" - 启动银联正式环境 "01" - 连接银联测试环境 测试用 卡号:6226440123456785 * 密码:111101 *****************************************************************/ private final static String mMode = "01"; private static final String TN_URL_01 = "http://202.101.25.178:8080/sim/gettn"; private static ProgressDialog mLoadingDialog = null; private static Activity activity; private static UnionPay unionPay = new UnionPay(); public static void unionpay(Activity activity) { UnionPay.activity = activity; mLoadingDialog = ProgressDialog.show(activity, // context "", // title "正在努力的获取tn中,请稍候...", // message true); // 进度是否是不确定的,这只和创建进度条有关 /************************************************* * 步骤1:从网络开始,获取交易流水号即TN ************************************************/ new Thread(unionPay).start(); // //支付金额 订单金额 // String orderAmount = "1533"; // //千引商户号 // String merchantNO = "805920100000069"; // //商户订单号 // String orderNO = "467934311"; // //通知Url // String backUrl = "http://www.baidu.com"; // //签名密钥 // String key = "86Aab696Fed90bc691a7AfE0b6a269Ac"; // //签名字段 // String signcont = // merchantNO+"&"+orderNO+"&"+orderAmount+"&"+backUrl+"&"+key; // // Log.e("", ""+signcont); // // String sign = MD5.digest(signcont); // // String sign = MD5Utils.generate(signcont); // Log.e("", "sign = "+sign.length()); // String url = "http://mpay.sinoqy.com:6283/qyapi/trans/getTn" // + "?orderAmount="+orderAmount // + "&merchantNO="+merchantNO // + "&orderNO="+ orderNO // + "&backUrl="+backUrl // + "&Sign="+ sign; // // Log.e("", ""+url); // // //获取TN // HTTPUtils.get(this, url , new VolleyListener() { // // @Override // public void onErrorResponse(VolleyError arg0) { // Log.e("", "VolleyError= "+arg0); // } // // @Override // public void onResponse(String arg0) { // Log.e("", "onResponse= "+arg0); // } // }); // } // 银联 private static Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { if (mLoadingDialog.isShowing()) { mLoadingDialog.dismiss(); } String tn = ""; if (msg.obj == null || ((String) msg.obj).length() == 0) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle("错误提示"); builder.setMessage("网络连接失败,请重试!"); builder.setNegativeButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } else { tn = (String) msg.obj; /************************************************* * 步骤2:通过银联工具类启动支付插件 ************************************************/ doStartUnionPayPlugin(activity, tn, mMode); } } }; // 银联 public static void doStartUnionPayPlugin(Activity activity, String tn, String mode) { Log.e("", "handleMessage"); // TODO // orderInfo ——订单信息为交易流水号,即TN。 // mode —— 银联后台环境标识,“00”将在银联正式环境发起交易, “01”将在 // 银联测试环境发起交易 UPPayAssistEx.startPayByJAR(activity, PayActivity.class, null, null, tn, mode); } @Override public void run() { Log.e("", "run"); String tn = null; InputStream is; try { String url = TN_URL_01; URL myURL = new URL(url); URLConnection ucon = myURL.openConnection(); ucon.setConnectTimeout(120000); is = ucon.getInputStream(); int i = -1; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((i = is.read()) != -1) { baos.write(i); } tn = baos.toString(); is.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } Message msg = mHandler.obtainMessage(); msg.obj = tn; mHandler.sendMessage(msg); } }
创新互联是专业的天元网站建设公司,天元接单;提供成都网站制作、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行天元网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
这是我自己整合的银联支付,在
package com.example.ex_example; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v){ //调用 UnionPay.unionpay(this); } }
出现如下异常:
找了N久才找到问题:(该死的这文件没考)
希望大家注意。