Java Code Examples for com.alipay.api.internal.util.AlipayLogger#logBizError()
The following examples show how to use
com.alipay.api.internal.util.AlipayLogger#logBizError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlipayMsgClient.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
public void run() { try { if (isConnected()) { webSocketConnector.sendPing(); reConnectTimes = 0; } else { ReconnectStrategy[] strategies = ReconnectStrategy.values(); while ((!isConnected()) && (System.currentTimeMillis() - waitTime >= strategies[reConnectTimes].getWatiTime())) { doConnect(); waitTime = System.currentTimeMillis(); reConnectTimes = (++reConnectTimes) % strategies.length; } } } catch (Throwable t) { AlipayLogger.logBizError(t); } }
Example 2
Source File: SM2Encryptor.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
protected String doDecrypt(String cipherTextBase64, String charset, String privateKey) throws Exception { //加载私钥参数 byte[] cipher = Base64.decodeBase64String(cipherTextBase64); byte[] privateKeyByte = Base64.decodeBase64String(privateKey); // 解析X509格式SM2私钥 PrivateKey sm2PrivateKey = parsePKCS8PrivateKey(privateKeyByte); // 使用SM2私钥解密 byte[] buf = sm2Decrypt(cipher, sm2PrivateKey); //将解密后的明文按指定字符集编码后返回 try { String strContent = new String(buf, charset); return strContent; } catch (UnsupportedEncodingException e) { AlipayLogger.logBizError(e); throw new AlipayApiException(e); } }
Example 3
Source File: SM2Encryptor.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
private static byte[] sm2Sign(byte[] message, PrivateKey sm2PrivateKey, String sm2UserId) throws AlipayApiException { try { String userId = "1234567812345678"; if (!StringUtils.isEmpty(sm2UserId)) { userId = sm2UserId; } Signature sm2SignEngine = Signature.getInstance("SM3withSM2"); sm2SignEngine.setParameter(new SM2ParameterSpec( Strings.toByteArray(userId))); sm2SignEngine.initSign(sm2PrivateKey); sm2SignEngine.update(message); return sm2SignEngine.sign(); } catch (Exception e) { AlipayLogger.logBizError(e); throw new AlipayApiException(e); } }
Example 4
Source File: SM2Encryptor.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
private static boolean sm2Verify(byte[] signature, byte[] message, PublicKey publicKey, String sm2UserId) { try { String userId = "1234567812345678"; if (!StringUtils.isEmpty(sm2UserId)) { userId = sm2UserId; } Signature sm2SignEngine = Signature.getInstance("SM3withSM2"); sm2SignEngine.setParameter(new SM2ParameterSpec(Strings.toByteArray(userId))); sm2SignEngine.initVerify(publicKey); sm2SignEngine.update(message); return sm2SignEngine.verify(signature); } catch (Exception e) { AlipayLogger.logBizError(e); return false; } }
Example 5
Source File: SM2Encryptor.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
protected boolean doVerify(String content, String charset, String publicKey, String sign) throws Exception { // 使用SM2公钥验签 byte[] signature = Base64.decodeBase64String(sign); byte[] message = content.getBytes(charset); byte[] publicKeyByte = Base64.decodeBase64String(publicKey); PublicKey sm2PublicKey = parseX509PublicKey(publicKeyByte); boolean valid = sm2Verify(signature, message, sm2PublicKey, null); if (!valid) { AlipayLogger.logBizError("验签失败"); } return valid; }
Example 6
Source File: SM2Encryptor.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
private static byte[] sm2Encrypt(byte[] plain, PublicKey sm2PublicKey) throws AlipayApiException { try { Cipher sm2CipherEngine = Cipher.getInstance("SM2", "BC"); sm2CipherEngine.init(Cipher.ENCRYPT_MODE, sm2PublicKey); return sm2CipherEngine.doFinal(plain); } catch (Exception e) { AlipayLogger.logBizError(e); throw new AlipayApiException(e); } }
Example 7
Source File: SM2Encryptor.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
private static byte[] sm2Decrypt(byte[] cipher, PrivateKey sm2PrivateKey) throws AlipayApiException { try { Cipher sm2CipherEngine = Cipher.getInstance("SM2", "BC"); sm2CipherEngine.init(Cipher.DECRYPT_MODE, sm2PrivateKey); return sm2CipherEngine.doFinal(cipher); } catch (Exception e) { AlipayLogger.logBizError(e); throw new AlipayApiException(e); } }
Example 8
Source File: MsgConnector.java From alipay-sdk-java-all with Apache License 2.0 | 4 votes |
public void onError(Exception ex) { AlipayLogger.logBizError(ex); }
Example 9
Source File: AlipayMsgClient.java From alipay-sdk-java-all with Apache License 2.0 | 4 votes |
public ProduceMsgAck sendMessage(AlipayRequest msgReq) throws InterruptedException { if (!isConnected()) { throw new NotYetConnectedException(); } Message message = new Message(); message.setxCmd(MsgConstants.MSG_CMD_PRODUCE); message.setxSignType(signType); message.setxCharset(charset); message.setAppId(appId); message.setMsgApi(msgReq.getApiMethodName()); message.setxTimestamp(System.currentTimeMillis()); message.setBizContent(new JSONWriter().write(msgReq.getBizModel(), true)); Message.addSign(message, appPrivateKey); ProtocolData protocolData = new ProtocolData(); protocolData.setMessage(message); CountDownLatch signal = new CountDownLatch(1); ProtocolDataContext protocolDataContext = new ProtocolDataContext(); protocolDataContext.setSendData(protocolData); protocolDataContext.setSendSignal(signal); if (!sendingQueue.offer(protocolData.getStreamId(), 200, TimeUnit.MILLISECONDS)) { throw new RuntimeException("too many message not receive ack, refuse new send. streamId:" + protocolData.getStreamId()); } sendingContexts.put(protocolData.getStreamId(), protocolDataContext); String protocolDataStr = ProtocolData.toStr(protocolData); if (AlipayLogger.isBizDebugEnabled()) { AlipayLogger.logBizDebug("send msg:" + protocolDataStr.replaceAll("[\r\n]", " ")); } webSocketConnector.send(ProtocolData.toStr(protocolData)); boolean signalNotify = signal.await(10000, TimeUnit.MILLISECONDS); sendingQueue.remove(protocolData.getStreamId()); sendingContexts.remove(protocolData.getStreamId()); if (!signalNotify) { AlipayLogger.logBizError("wait ack timeout(10s). streamId:" + protocolData.getStreamId()); throw new RuntimeException("wait ack timeout(10s). streamId:" + protocolData.getStreamId()); } ProtocolData ackData = protocolDataContext.getAckData(); if (ackData == null) { throw new RuntimeException("ack protocol data null. streamId:" + protocolData.getStreamId()); } Message ackMsg = ackData.getMessage(); if (ackMsg == null) { throw new RuntimeException("ack msg null. streamId:" + protocolData.getStreamId()); } ProduceMsgAck produceMsgAck = new ProduceMsgAck(); produceMsgAck.setxStatus(MsgStatusEnum.fromStr(ackMsg.getxStatus())); produceMsgAck.setxCode(ackMsg.getxCode()); produceMsgAck.setxError(ackMsg.getxError()); produceMsgAck.setxMessageId(ackMsg.getxMessageId()); return produceMsgAck; }