Android集成PhonePe支付网关时出现400错误求助
PhonePe Android PG SDK集成报错「Something went wrong:400」
我按照PhonePe官方文档集成Android端PG SDK,目前遇到「Something went wrong:400」错误,预期实现唤起UPI应用完成支付并获取成功响应,以下是我的集成代码及Manifest配置:
集成代码
data.put("merchantTransactionId", getTransactionId); data.put("merchantId", R.string.merchantid); data.put("merchantUserId","ABC12345")); data.put("amount", 2); data.put("mobileNumber", "123456789"); data.put("callbackUrl", "https://webhook.site/callback-url"); data.put("redirectMode", "POST"); data.put("redirectUrl", "https://webhook.site/redirect-url"); PaymentInstrument mPaymentInstrument = new PaymentInstrument(); mPaymentInstrument.setType("UPI_INTENT"); mPaymentInstrument.setTargetApp("com.phonepe.app"); data.put("paymentInstrument", mPaymentInstrument); DeviceContext mDeviceContext = new DeviceContext(); mDeviceContext.setDeviceOs("ANDROID"); data.put("deviceContext", mDeviceContext); String json = gson.toJson(data); String getdatas = new String(Base64.encode(json.getBytes(),Base64.DEFAULT), Base64.DEFAULT); try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } String input = (getdatas + apiEndPoint + salt) ; // compute the hash of the input string byte[] hash = md.digest(input.getBytes()); // convert the hash to a hexadecimal string StringBuilder hexString = new StringBuilder(); for (byte b : hash) { hexString.append(String.format("%02x", b)); } String checksum = String.valueOf(hexString); String checkSumResult=checksum+ "###" + saltIndex; B2BPGRequest b2BPGRequest = new B2BPGRequestBuilder().setData(getdatas).setChecksum(checkSumResult).setUrl(apiEndPoint) .build(); try { startActivityForResult(PhonePe.getImplicitIntent(this, b2BPGRequest, "com.phonepe.app"), B2B_PG_REQUEST_CODE); } catch (PhonePeInitException e) { }
Manifest配置
<meta-data android:name="com.phonepe.android.sdk.Debuggable" android:value="true"/> <!-- Keep it true in UAT environment for both the flags--> <meta-data android:name="com.phonepe.android.sdk.isUAT" android:value="true"/> <meta-data android:name="com.phonepe.android.sdk.isSimulator" android:value="true"/> <!-- The value will be the MID--> <meta-data android:name="com.phonepe.android.sdk.MerchantId" android:value="@string/merchantid"/>
可能的问题及修复方案
- 商户ID赋值错误:代码中
data.put("merchantId", R.string.merchantid)传的是资源ID而非实际商户ID字符串,需改为getString(R.string.merchantid)获取真实值。 - 金额单位错误:PhonePe金额以派萨为最小单位,传
2仅代表0.02卢比,不符合支付要求,需将金额乘以100(如2卢比传200)。 - Base64编码格式问题:使用
Base64.DEFAULT会生成换行符,可能导致校验失败,替换为Base64.NO_WRAP避免格式异常。 - Checksum计算验证:确认
apiEndPoint为UAT环境正确端点,salt和saltIndex与商户后台配置完全匹配,输入字符串顺序必须严格为Base64编码的data + apiEndPoint + salt。 - 环境配置冲突:
isSimulator设为true是模拟环境,真实设备测试时需改为false,避免环境不匹配。 - 回调URL有效性:确保
callbackUrl和redirectUrl为UAT环境可访问的公网地址,无法访问会导致回调失败。
内容的提问来源于stack exchange,提问作者Selva Meena
相关产品推荐
相关产品推荐

