Android Volley com.android.volley.NoConnectionError:javax.net.ssl.SSLHandshakeException:javax.net.ssl.SSLProtocolException:SSL握手已中止

时间:2015-05-19 06:32:52

标签: android android-volley

在我的新应用中,我必须通过支付网关进行付款, 因此,在使用凌空调用支付网关时,我遇到了此错误,

com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x632a40e0: Failure in SSL library, usually a protocol error
error:14077102:SSL routines:SSL23_GET_SERVER_HELLO:unsupported protocol (external/openssl/ssl/s23_clnt.c:714 0x5b66cd74:0x00000000)

我用谷歌搜索了http://stackoverflow.com/questions/22564317/https-support-for-volley-android-networking-library,但我无法让它发挥作用, 任何帮助将不胜感激,提前致谢。

这是我的代码:

public class PaymentActivity extends ActionBarActivity {
    String merchantId = "xxxxxxxxxxxxx";
    String key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    String message = "123456|AED|1000.00|http://www.merchantmoney.com/shop/success.jsp|http://www.merchantmoney.com/shop/fail.jsp|01|Internet|||||||||||||||||||||||||||||||||||||||||||||";
    String url = "https://test.timesofmoney.com/direcpay";
    private Button paymentButton;
    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payment);
        paymentButton = (Button) findViewById(R.id.payment_btn);
        progressBar = (ProgressBar) findViewById(R.id.progress);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        EncDec encDec = new EncDec(key);
        String encryptMessage = encDec.encrypt(message);
        final String requestParameter = merchantId + "|" + encryptMessage;
        final PaymentRequest request = new PaymentRequest();
        request.setRequestParameter(requestParameter);
        paymentButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                progressBar.setVisibility(View.VISIBLE);
                PaymentManager.executePaymentService(getBaseContext(), request,
                        listener);
            }
        });
    }

    PaymentListener listener = new PaymentListener() {

        @Override
        public void onResponse(PaymentResponse response) {

        }

        @Override
        public void onInterNetConnectionFailured() {

        }

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    };

}

PaymentManager:

public class PaymentManager {
    public static void executePaymentService(Context context,
            final PaymentRequest request,
            final BaseResponseListener<PaymentResponse> responseListener) {
        String url = "https://test.timesofmoney.com/direcpay";
        ErrorListener errorListener = new ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError volleyError) {
                responseListener.onErrorResponse(volleyError);

            }
        };

        Listener<String> listener = new Response.Listener<String>() {

            @Override
            public void onResponse(String string) {
                responseListener.onResponse(new Gson().fromJson(string,
                        PaymentResponse.class));
            }

        };
        MyStringRequest loginReq = new MyStringRequest(Method.POST, url,
                listener, errorListener) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("requestParameter", request.getRequestParameter());
                return hashMap;
            }
        };

        try {
            NetworkManager.executeStringReq(context, loginReq);
        } catch (NoInternetConnectionException e) {
            e.printStackTrace();
            responseListener.onInterNetConnectionFailured();
        }

    }
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,在我的情况下是服务器端问题(无法验证第一个证书)。 检查一下:

https://steveliles.github.io/android_ssl_certificate_not_trusted.html

希望得到这个帮助。