Common mistakes are strongly recommended to read and then do to avoid stepping on pit spend more money

1. The ID has not completed WeChat authentication, please confirm and try again

Completed appid certification, WeChat service number for enterprise certification, open platform for developer certification.

2. The APPID authentication subject name you entered is inconsistent with the actual authentication subject name, please check the modification and try again

Check whether the open platform or public platform authentication subject is consistent with the merchant number subject.

3. Associating this type of AppID is not supported

WeChat Native payment (PC site) cannot use the open platform appid. The AppID of WeChat Native payment must be ** WeChat service number **, that is, the public number of the authentication subject of the enterprise. The AppID of WeChat Native payment must be ** WeChat service number **, that is, the public number of the authentication subject of the enterprise. The AppID of WeChat Native payment must be ** WeChat service number **, that is, the public number of the authentication subject of the enterprise.

4. Modify the name of the receiver presented when payment is made

The name of the receiver should be changed to the abbreviation of the merchant inside the merchant number

WeChat Native payment application process

1. Apply for WeChat merchant number 2. Apply for WeChat enterprise service number and get certification, get APPID 3. Bind the APPID of service number with merchant number 4

WeChat Native payment access

Java development recommends using IJPay 1, the introduction of IJPay library

< the dependency > < groupId > com. Making. Javen205 < / groupId > < artifactId > IJPay - WxPay < / artifactId > < version > 2.7.3 < / version > </dependency>

2. Create the parameter class required by the request. The configuration information is in Application

Public class wxPayConfig {/** * @value ("${wx.pay.appid}"); public class wxPayConfig {/** * @value ("${wx.pay.appid}"); /** * @value ("${wx.pay.mchid}"); /** @value ("${wx.pay.mchid}"); /** * @value ("${wx.pay.mchKey}"); /** @value ("${wx.pay.mchKey}"); /** * Async callback address */ @Value("${wx.pay.notifyUrl}") private String NotifyUrl; }

3, Configuration Information Application.Properties

Wxpay. appID = AppID wxpay.appSecret= AppSecret wxpay. McHID = Merchant wxpay.partnerKey= PartnerKey of Merchant Number Wxpay. certPath= Merchant No. P12 Certificate wxpay.domain= Asynchronous verification notification URL of payment completed by scanning code

4, unified order

Map<String, String> params = UnifiedOrderModel .builder() .appid(wxPayConfig.appId) .mch_id(wxPayConfig.mchId) Nonce_str (WxPayKit. GenerateStr ()). The body (" zhao tangyuan payment "). The attach (" zhao tangyuan pay on pit "). Out_trade_no (createOrderRequestDto. GetId ()) .total_fee(total_fee) .spbill_create_ip(ip) .notify_url(wxPayConfig.domain) .trade_type(TradeType.NATIVE.getTradeType())  .build() .createSign(wxPayConfig.partnerKey, SignType.HMACSHA256); String xmlResult = WxPayApi.pushOrder(false, params); Map<String, String> result = WxPayKit.xmlToMap(xmlResult); String returnCode = result.get("return_code"); String returnMsg = result.get("return_msg"); System.out.println(returnMsg); if (! WxPaykit.codeisok (returnCode)) {// Replace the exception status with your own throw New ServiceException(errorTypeEnum.Recharge_Error); } String resultCode = result.get("result_code"); if (! WxPaykit.codeisok (resultCode)) {// Replace the exception status with your own throw New ServiceException(errorTypeEnum.Recharge_Error); } // generate pre-paid order success String qrCodeUrl = result.get(" Code_Url "); Try {// generate a single QR code and return it to the client with ByteArrayOutputStream out = new ByteArrayOutputStream(); QrCodeKit.encodeOutPutSteam(out, qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, "png", 200, 200); BASE64Encoder encoder = new BASE64Encoder(); imgBase64Str = encoder.encode(out.toByteArray()); } catch (IOException e) { e.printStackTrace(); } return imgBase64Str;
Java String xmlMsg = httpkit.readData (request); Logger.info (" payment notification =" + XMLMsg); Map<String, String> params = WxPayKit.xmlToMap(xmlMsg); String returnCode = params.get("return_code"); // Note the situation of repeated notification, the same order number may receive more than one notification, If (WxPayKit. VerifyNotify (params, wxpayconfig.partnerKey, wxpayconfig.partnerKey) SignType.hmacSHA256)) {if (wxPaykit.codeisok (returnCode)) {String out_trade_no = params.get("out_trade_no"); String total_fee = params.get("total_fee"); Map<String, String> xml = new HashMap<String, String>(2); xml.put("return_code", "SUCCESS"); xml.put("return_msg", "OK"); return WxPayKit.toXml(xml); }}