- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是支付网关的新手。目前,我正在开发一个移动应用程序,我需要在 Android 应用程序中集成 PayU 支付网关。
到目前为止,我已经为 TEST url 创建了一个代码,当我运行我的应用程序时,我遇到了以下异常:
发生错误。抱歉,出现问题。
手机应用截图
这是我的代码:
public class PayMentGateWay extends Activity {
private ArrayList<String> post_val = new ArrayList<String>();
private String post_Data="";
WebView webView ;
final Activity activity = this;
private String tag = "PayMentGateWay";
private String hash,hashSequence;
String merchant_key="JBZaLc";
String salt="GQs7yium";
String action1 ="";
String base_url="https://test.payu.in";
int error=0;
String hashString="";
Map<String,String> params;
String txnid ="";
Handler mHandler = new Handler();
@SuppressLint("JavascriptInterface")
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
final ProgressDialog progressDialog = new ProgressDialog(activity);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
webView = new WebView(this);
setContentView(webView);
post_val.add("key");
post_val.add("JBZaLc");
post_val.add("txnid");
post_val.add("5d59dae66618a14f5020");
post_val.add("amount");
post_val.add("100.00");
post_val.add("productinfo");
post_val.add("{paymentParts:[{name:abc,description:abcd,value:500,isRequired:true,settlementEvent:EmailConfirmation}], paymentIdentifiers:[{field:CompletionDate, value:25/06/2015}]}");
post_val.add("firstname");
post_val.add("pqrs");
post_val.add("email");
post_val.add("xxxx@xxxmail.com");
post_val.add("phone");
post_val.add("xxxxxxxxxx");
post_val.add("surl");
post_val.add("https://www.google.com");
post_val.add("furl");
post_val.add("https://www.gmail.com");
post_val.add("hash");
post_val.add("");
post_val.add("provider");
post_val.add("payu_paisa");
Log.d(tag, "post_val: "+post_val);
params= new HashMap<String,String>();
for(int i = 0;i<post_val.size();){
params.put(post_val.get(i), post_val.get(i+1));
i+=2;
}
if(empty(params.get("txnid"))){
Random rand = new Random();
String rndm = Integer.toString(rand.nextInt())+(System.currentTimeMillis() / 1000L);
txnid=hashCal("SHA-256",rndm).substring(0,20);
popup("txnid : " + txnid);
System.out.println("......txnid...... " + txnid);
} else {
txnid=params.get("txnid");
System.out.println("....else.......txnid...... " + txnid);
}
//String udf2 = txnid;
String txn="abcd";
hash="";
String hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty(params.get("hash")) && params.size()>0) {
if( empty(params.get("key"))
|| empty(params.get("txnid"))
|| empty(params.get("amount"))
|| empty(params.get("firstname"))
|| empty(params.get("email"))
|| empty(params.get("phone"))
|| empty(params.get("productinfo"))
|| empty(params.get("surl"))
|| empty(params.get("furl"))
|| empty(params.get("service_provider"))
) {
String[] hashVarSeq = hashSequence.split("\\|");
for (int i = 0; i < hashVarSeq.length; i++) {
System.out.println("<<<<<>>>>>>>> " + hashVarSeq[i]);
}
for(String part : hashVarSeq)
{
hashString= (empty(params.get(part))) ? hashString.concat("") : hashString.concat(params.get(part));
hashString=hashString.concat("|");
System.out.println("??????? " + hashString);
}
hashString=hashString.concat(salt);
hash=hashCal("SHA-512",hashString);
System.out.println(hashString + " /////~~~~~~ " + hash);
action1=base_url.concat("/_payment");
}
}
else if(!empty(params.get("hash")))
{
hash=params.get("hash");
action1=base_url.concat("/_payment");
System.out.println("!!!!!!!!HASHHHHHHH!!!!!! " + hash);
}
webView.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>onReceivedError>>>>>>>>>>>>>>>>>>");
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>onReceivedSslError>>>>>>>>>>>>>>>>>>");
Toast.makeText(activity, "SslError! " + error, Toast.LENGTH_SHORT).show();
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>shouldOverrideUrlLoading>>>>>>>>>>>>>>>>>>");
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
System.out.println(">>>>>>>>>>>>>>onPageFinished>>>>>>>>>>>>>>>>>>");
}
});
webView.setVisibility(0);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setCacheMode(2);
webView.getSettings().setDomStorageEnabled(true);
webView.clearHistory();
webView.clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(false);
webView.getSettings().setLoadWithOverviewMode(false);
webView.addJavascriptInterface(new PayUJavaScriptInterface(activity), "PayUMoney");
Map<String, String> mapParams = new HashMap<String, String>();
mapParams.put("key",merchant_key);
mapParams.put("hash",PayMentGateWay.this.hash);
mapParams.put("txnid",(empty(PayMentGateWay.this.params.get("txnid"))) ? "" : PayMentGateWay.this.params.get("txnid"));
Log.d(tag, "txnid: "+PayMentGateWay.this.params.get("txnid"));
mapParams.put("service_provider","payu_paisa");
mapParams.put("amount",(empty(PayMentGateWay.this.params.get("amount"))) ? "" : PayMentGateWay.this.params.get("amount"));
mapParams.put("firstname",(empty(PayMentGateWay.this.params.get("firstname"))) ? "" : PayMentGateWay.this.params.get("firstname"));
mapParams.put("email",(empty(PayMentGateWay.this.params.get("email"))) ? "" : PayMentGateWay.this.params.get("email"));
mapParams.put("phone",(empty(PayMentGateWay.this.params.get("phone"))) ? "" : PayMentGateWay.this.params.get("phone"));
mapParams.put("productinfo",(empty(PayMentGateWay.this.params.get("productinfo"))) ? "" : PayMentGateWay.this.params.get("productinfo"));
mapParams.put("surl",(empty(PayMentGateWay.this.params.get("surl"))) ? "" : PayMentGateWay.this.params.get("surl"));
mapParams.put("furl",(empty(PayMentGateWay.this.params.get("furl"))) ? "" : PayMentGateWay.this.params.get("furl"));
mapParams.put("lastname",(empty(PayMentGateWay.this.params.get("lastname"))) ? "" : PayMentGateWay.this.params.get("lastname"));
mapParams.put("address1",(empty(PayMentGateWay.this.params.get("address1"))) ? "" : PayMentGateWay.this.params.get("address1"));
mapParams.put("address2",(empty(PayMentGateWay.this.params.get("address2"))) ? "" : PayMentGateWay.this.params.get("address2"));
mapParams.put("city",(empty(PayMentGateWay.this.params.get("city"))) ? "" : PayMentGateWay.this.params.get("city"));
mapParams.put("state",(empty(PayMentGateWay.this.params.get("state"))) ? "" : PayMentGateWay.this.params.get("state"));
mapParams.put("country",(empty(PayMentGateWay.this.params.get("country"))) ? "" : PayMentGateWay.this.params.get("country"));
mapParams.put("zipcode",(empty(PayMentGateWay.this.params.get("zipcode"))) ? "" : PayMentGateWay.this.params.get("zipcode"));
mapParams.put("udf1",(empty(PayMentGateWay.this.params.get("udf1"))) ? "" : PayMentGateWay.this.params.get("udf1"));
mapParams.put("udf2",(empty(PayMentGateWay.this.params.get("udf2"))) ? "" : PayMentGateWay.this.params.get("udf2"));
mapParams.put("udf3",(empty(PayMentGateWay.this.params.get("udf3"))) ? "" : PayMentGateWay.this.params.get("udf3"));
mapParams.put("udf4",(empty(PayMentGateWay.this.params.get("udf4"))) ? "" : PayMentGateWay.this.params.get("udf4"));
mapParams.put("udf5",(empty(PayMentGateWay.this.params.get("udf5"))) ? "" : PayMentGateWay.this.params.get("udf5"));
mapParams.put("pg",(empty(PayMentGateWay.this.params.get("pg"))) ? "" : PayMentGateWay.this.params.get("pg"));
webview_ClientPost(webView, action1, mapParams.entrySet());
}
public class PayUJavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context */
PayUJavaScriptInterface(Context c) {
mContext = c;
}
public void success(long id, final String paymentId) {
mHandler.post(new Runnable() {
public void run() {
mHandler = null;
Intent intent = new Intent(PayMentGateWay.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("result", "success");
intent.putExtra("paymentId", paymentId);
startActivity(intent);
finish();
}
});
}
}
public void webview_ClientPost(WebView webView, String url, Collection< Map.Entry<String, String>> postData){
StringBuilder sb = new StringBuilder();
sb.append("<html><head></head>");
sb.append("<body onload='form1.submit()'>");
sb.append(String.format("<form id='form1' action='%s' method='%s'>", url, "post"));
for (Map.Entry<String, String> item : postData) {
sb.append(String.format("<input name='%s' type='hidden' value='%s' />", item.getKey(), item.getValue()));
}
sb.append("</form></body></html>");
Log.d(tag, "webview_ClientPost called");
webView.loadData(sb.toString(), "text/html", "utf-8");
}
public void success(long id, final String paymentId) {
mHandler.post(new Runnable() {
public void run() {
mHandler = null;
Intent intent = new Intent(PayMentGateWay.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Constants.ACCOUNT_NAME, "success");
intent.putExtra(Constants._ID, paymentId);
startActivity(intent);
finish();
}
});
}
public boolean empty(String s)
{
if(s== null || s.trim().equals(""))
return true;
else
return false;
}
public String hashCal(String type,String str){
byte[] hashseq=str.getBytes();
StringBuffer hexString = new StringBuffer();
try{
MessageDigest algorithm = MessageDigest.getInstance(type);
algorithm.reset();
algorithm.update(hashseq);
byte messageDigest[] = algorithm.digest();
for (int i=0;i<messageDigest.length;i++) {
String hex=Integer.toHexString(0xFF & messageDigest[i]);
if(hex.length()==1) hexString.append("0");
hexString.append(hex);
}
}catch(NoSuchAlgorithmException nsae){ }
return hexString.toString();
}
public void popup(String msg) {
Toast.makeText(PayMentGateWay.this, "" + msg, Toast.LENGTH_LONG).show();
}
}
我真的不知道确切的问题是什么。为什么我看不到下一页或者我错过了什么?
最佳答案
我认为你的代码没问题,我也在做同样的事情,从 payu 那里得知 test merchant_key 和 salt 不起作用目前。尝试生产模式。
如果你想从服务器使用(postUrl)加载数据:
post_Data = "hash="+PayMentGateWay.this.hash+"&key="+merchant_key+"&txnid="+PayMentGateWay.this.params.get("txnid")+"&amount="+PayMentGateWay.this.params.get("amount")+
"&productinfo="+PayMentGateWay.this.params.get("productinfo")+"&firstname="+PayMentGateWay.this.params.get("firstname")+
"&email="+PayMentGateWay.this.params.get("email")+"&phone="+PayMentGateWay.this.params.get("phone")+
"&surl="+PayMentGateWay.this.params.get("surl")+"&furl="+ PayMentGateWay.this.params.get("furl")+
"&service_provider="+ "payu_paisa";
webView.postUrl("https://secure.payu.in/_payment", EncodingUtils.getBytes(post_Data, "base64"));
希望对您有所帮助。
关于android - 如何在 Android 应用程序中集成 TEST PayU 支付网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31046696/
我最近在/ drawable中添加了一些.gifs,以便可以将它们与按钮一起使用。这个工作正常(没有错误)。现在,当我重建/运行我的应用程序时,出现以下错误: Error: Gradle: Execu
Android 中有返回内部存储数据路径的方法吗? 我有 2 部 Android 智能手机(Samsung s2 和 s7 edge),我在其中安装了一个应用程序。我想使用位于这条路径中的 sqlit
这个问题在这里已经有了答案: What's the difference between "?android:" and "@android:" in an android layout xml f
我只想知道 android 开发手机、android 普通手机和 android root 手机之间的实际区别。 我们不能从实体店或除 android marketplace 以外的其他地方购买开发手
自Gradle更新以来,我正在努力使这个项目达到标准。这是一个团队项目,它使用的是android-apt插件。我已经进行了必要的语法更改(编译->实现和apt->注释处理器),但是编译器仍在告诉我存在
我是android和kotlin的新手,所以请原谅要解决的一个非常简单的问题! 我已经使用导航体系结构组件创建了一个基本应用程序,使用了底部的导航栏和三个导航选项。每个导航选项都指向一个专用片段,该片
我目前正在使用 Facebook official SDK for Android . 我现在正在使用高级示例应用程序,但我不知道如何让它获取应用程序墙/流/状态而不是登录的用户。 这可能吗?在那种情
我在下载文件时遇到问题, 我可以在模拟器中下载文件,但无法在手机上使用。我已经定义了上网和写入 SD 卡的权限。 我在服务器上有一个 doc 文件,如果用户单击下载。它下载文件。这在模拟器中工作正常但
这个问题在这里已经有了答案: What is the difference between gravity and layout_gravity in Android? (22 个答案) 关闭 9
任何人都可以告诉我什么是 android 缓存和应用程序缓存,因为当我们谈论缓存清理应用程序时,它的作用是,缓存清理概念是清理应用程序缓存还是像内存管理一样主存储、RAM、缓存是不同的并且据我所知,缓
假设应用程序 Foo 和 Eggs 在同一台 Android 设备上。任一应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已经运行以及运行了多长时间? 最佳答案
我有点困惑,我只看到了从 android 到 pc 或者从 android 到 pc 的例子。我需要制作一个从两部手机 (android) 连接的 android 应用程序进行视频聊天。我在想,我知道
用于使用 Android 以编程方式锁定屏幕。我从 Stackoverflow 之前关于此的问题中得到了一些好主意,并且我做得很好,但是当我运行该代码时,没有异常和错误。而且,屏幕没有锁定。请在这段代
文档说: android:layout_alignParentStart If true, makes the start edge of this view match the start edge
我不知道这两个属性和高度之间的区别。 以一个TextView为例,如果我将它的layout_width设置为wrap_content,并将它的width设置为50 dip,会发生什么情况? 最佳答案
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我是新手,正在尝试理解以下 XML 代码: 查看 developer.android.com 上的文档,它说“starStyle”是 R.attr 中的常量, public static final
在下面的代码中,为什么当我设置时单选按钮的外观会发生变化 android:layout_width="fill_parent" 和 android:width="fill_parent" 我说的是
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
假设我有一个函数 fun myFunction(name:String, email:String){},当我调用这个函数时 myFunction('Ali', 'ali@test.com ') 如何
我是一名优秀的程序员,十分优秀!