In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The purpose of this article is to share with you the content of the example analysis on the development of cash red packets by Wechat official account. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
This article is about the payment tools of Wechat merchants-cash red envelopes.
Cash red packet. Png
Preparatory work
[official documentation]
First, open the right of cash red packet
Before using cash red packet, please go to activate the cash red packet function. Operation path: [log in to WeChat Pay merchant platform-- > Product Center-- > Cash red packet-- > activate].
Download the API certificate
When a merchant calls the WeChat red packet API, the server will verify the certificate. Please download the certificate on the merchant platform.
Cash red packet-download certificate .png
Cash red packet-the downloaded file. Png
Some people want to ask which one should be used for so many certificates? Does it have anything to do with the development language?
You can refer to the certificate description in the screenshot .txt for what language and what certificate to use.
The contents are as follows:
Welcome to WeChat Pay! WeChat Pay API has a total of four copies (certificate pkcs12 format, certificate pem format, certificate key pem format, CA certificate), which are the certificate files that need to be carried when required in the API. The certificate belongs to sensitive information, please take good care of it and don't disclose it and be copied by others. The certificate format is different in different development languages. Here are the instructions: certificate pkcs12 format (apiclient_cert.p12) contains private key information in the certificate file, in p12 (pfx) format, which is issued to you by WeChat Pay to identify and define your identity. API with higher security requirements needs to use this certificate to confirm your calling identity. On windows, you can directly double-click to import the system. During the import process, you will be prompted to enter the certificate password. The certificate password defaults to your merchant ID (for example: 10010000) Certificate pem format (apiclient_cert.pem) exports the certificate part of the file from apiclient_cert.p12 to pem format. Please take good care of it and do not disclose and copy part of the development language and environment. You can not directly use p12 files, but need to use pem, so for your convenience. It has been provided for you directly or you can use the openssl command to export it yourself: openssl pkcs12-clcerts-nokeys-in apiclient_cert.p12-out apiclient_cert.pem certificate key pem format (apiclient_key.pem) exports the key part of the file from apiclient_cert.p12, develops the language and environment for the pem format part, can not directly use the p12 file, but needs to use pem, so for your convenience It has been provided to you directly or you can use the openssl command to export it yourself: openssl pkcs12-nocerts-in apiclient_cert.p12-out apiclient_key.pem CA certificate (rootca.pem) WeChat Pay api server has also deployed a server certificate to prove the identity of WeChat Pay When you use api to make calls, you also need to verify the authenticity of the called server and domain name. This file is the root certificate of the authority that signed the WeChat Pay certificate. It can be used to verify the authenticity of WeChat Pay server certificate. Some environments and tools have built-in root certificates of several authorities, which can be verified normally without referring to the certificate. This is for you to load and use in an environment where there is no built-in required root certificate.
III. Recharge
Before handing out cash red envelopes, please make sure that you have sufficient funds. If not, please recharge. Operation path: [log in to Merchant platform-- > account Center-- > Fund Management-- > recharge]
The average amount of each red packet must be between 1.00 yuan and 200.00 yuan.
Cash red packet-recharge .png
4. Obtain openid
Currently, it is supported to distribute red packets of a specified amount to the openid of specified Wechat users. (for openid, please see the previously written article: develop the official account of Wechat with authorization to obtain user information.
V. setting of relevant parameters
Parameters related to red packets [mainly security: bind IP, prevent users from stealing], you can set and change them on the page.
The operation path is as follows: [log in to Merchant platform-> Product Center-> Cash Red packet-> Product Settings] (Note: the "Product Settings" operation button will appear only after you activate the cash red packet function).
You can set and change the following parameters:
Cash red packet-setting parameter .png
Description:
1. Call IP address: after setting, only the set IP address can be called, and the rest of the IP calls will report an error
2. Upper limit for users: limit the number of recipients on the same openid on the same day.
3. Anti-brushing level: anti-brushing refers to the interception of Wechat secondary account, zombie account, machine account and so on by Wechat risk control. You can control the anti-brushing intensity by changing the anti-brushing level.
At the same time, you can also apply for a change in the amount of red packets. However, it needs to be examined by WeChat Pay and will not take effect until it is approved.
Cash red packet category
Cash red packets are divided into two categories:
1. Ordinary red packets [official documents]
2. Fission red packet [official document]
Some parameters of the two are different.
Send cash red packets
1. The API com.javen.weixin.api.RedPackApi.java for sending ordinary red packets
Private static String sendRedPackUrl = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; / * * send red packet * @ param params request parameters * @ param certPath certificate file directory * @ param partner certificate password * @ return {String} * / public static String sendRedPack (Map params, String certPath, String partner) {return HttpUtils.postSSL (sendRedPackUrl, PaymentKit.toXml (params), certPath, partner);}
2. Send fission red packet interface com.javen.weixin.api.RedPackApi.java
Private static String sendGroupRedPackUrl = "api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack"; / * * send fission red packet * @ param params request parameter * @ param certPath certificate file directory * @ param partner certificate password * @ return {String} * / public static String sendGroupRedPack (Map params, String certPath, String partner) {return HttpUtils.postSSL (sendGroupRedPackUrl, PaymentKit.toXml (params), certPath, partner) }
Specific implementation of encapsulation com.javen.utils.ReadPackUtils.java
1. Ordinary red packets
/ * * send ordinary red packets * @ param request to get IP * @ param total_amount payment cash (unit points) * @ total number of param total_num red packets issued * @ param wishing red packet blessing words * @ param act_name event name * @ param remark remarks * @ param reOpenid user openid * @ param partner merchant number * @ param wxappid public account appid * @ param sendName merchant name * @ param paternerKey merchant signature key * @ param certPath certificate path * @ return * / public static boolean sendredpack (HttpServletRequest request String total_amount,String total_num,String wishing,String act_name,String remark,String reOpenid,String partner,String wxappid,String sendName,String paternerKey,String certPath) {/ / merchant order number String mchBillno = System.currentTimeMillis () + " String ip = IpKit.getRealIp (request); Map params = new HashMap (); / / Random string params.put ("nonce_str", System.currentTimeMillis () / 1000 + ""); / / merchant order number params.put ("mch_billno", mchBillno); / / merchant number params.put ("mch_id", partner) / / Public account ID params.put ("wxappid", wxappid); / / merchant name params.put ("send_name", sendName); / / user OPENID params.put ("re_openid", reOpenid); / / payment cash (unit points) params.put ("total_amount", total_amount) / / Total number of red packets distributed params.put ("total_num", total_num); / / Red packet blessing message params.put ("wishing", wishing); / / Terminal IP params.put ("client_ip", ip); / / event name params.put ("act_name", act_name) / / remarks params.put ("remark", remark); / / create signature String sign = PaymentKit.createSign (params, paternerKey); params.put ("sign", sign); String xmlResult = RedPackApi.sendRedPack (params, certPath, partner); Map result = PaymentKit.xmlToMap (xmlResult); log.warn (JsonKit.toJson (result)) / / this field is a communication ID, not a transaction ID. You need to check result_code to determine whether the transaction is successful or not: String return_code = result.get ("return_code"); / / Business result String result_code = result.get ("result_code"); if (StrKit.isBlank (return_code) | |! "SUCCESS" .equals (return_code)) {return false } if (StrKit.notBlank (result_code) & & "SUCCESS" .equals (result_code)) {return true;} return false;}
2. Fission red packet
/ * send fission red packets * @ param partner * @ param wxappid * @ param sendName * * @ param total_amount * @ param total_num * @ param wishing * @ param act_name * @ param remark * @ param paternerKey * @ return * / public static boolean sendGroupRedPack (String partner, String wxappid, String sendName, String reOpenid, String total_amount String total_num, String wishing, String act_name, String remark, String paternerKey, String certPath) {/ / merchant order number String mchBillno = System.currentTimeMillis () + " Map params = new HashMap (); / / Random string params.put ("nonce_str", System.currentTimeMillis () / 1000 + ""); / / merchant order number params.put ("mch_billno", mchBillno); / / merchant number params.put ("mch_id", partner) / / Public account ID params.put ("wxappid", wxappid); / / merchant name params.put ("send_name", sendName); / / user OPENID params.put ("re_openid", reOpenid); / / payment cash (unit points) params.put ("total_amount", total_amount) / / Total number of red packets distributed params.put ("total_num", total_num); / / Red packet amount setting method params.put ("amt_type", "ALL_RAND"); / / Red packet blessing params.put ("wishing", wishing); / / event name params.put ("act_name", act_name) / / remarks params.put ("remark", remark); / / create signature String sign = PaymentKit.createSign (params, paternerKey); params.put ("sign", sign); String xmlResult = RedPackApi.sendGroupRedPack (params, certPath, partner); Map result = PaymentKit.xmlToMap (xmlResult); log.warn (JsonKit.toJson (result)) / / this field is a communication ID, not a transaction ID. You need to check result_code to determine whether the transaction is successful or not: String return_code = result.get ("return_code"); / / Business result String result_code = result.get ("result_code"); if (StrKit.isBlank (return_code) | |! "SUCCESS" .equals (return_code)) {return false } if (StrKit.notBlank (result_code) & & "SUCCESS" .equals (result_code)) {return true;} return false;} send red packet Demo/** * WeChat red packet demo * @ author Javen * 28th May 2016 * / public class RedPackApiController extends Controller {private static String sendName = "Javen205" / / Wechat certificate path private static String certPath = "/ Users/Javen/Downloads/cert/apiclient_cert.p12"; / / merchant related information String wxappid = PropKit.get ("appId"); / / merchant ID String partner = PropKit.get ("mch_id") assigned by WeChat Pay; / / API key String paternerKey = PropKit.get ("paternerKey") / * send ordinary red packets * / public void sendredpack () {boolean isSend = ReadPackUtils.sendredpack (getRequest (), "100th", "1", "Thank you for participating in lantern riddle guessing activities, happy Lantern Festival to you!" "guess lantern riddles and grab red envelopes", "guess more and more, come and grab it!" , "o_pncsidC-pRRfCP4zj98h7slREw", partner, wxappid, sendName, paternerKey, certPath); renderJson (isSend) } / * send fission red packet * / public void sendGroupRedPack () {boolean isSend = ReadPackUtils.sendGroupRedPack (partner, wxappid, "Tianhong Department Store", "o_pncsidC-pRRfCP4zj98h7slREw", "100th", "10", "Thank you for participating in lantern riddle guessing activities, happy Lantern Festival!" , "guess lantern riddles and grab red envelopes", "guess more and certPath more", paternerKey, certPath); renderJson (isSend);} public void query () {String query = ReadPackUtils.query ("100000982014111234567890", partner, wxappid, paternerKey, certPath); renderJson (query);} query red packet records
[inquire about official documents of red packet records]
Interface encapsulation com.javen.weixin.api.RedPackApi.java
Private static String getHBInfo = "api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo" / * * query information according to merchant order number * @ param params request parameters * @ param certPath certificate file directory * @ param partner certificate password * @ return {String} * / public static String getHbInfo (Map params, String certPath, String partner) {return HttpUtils.postSSL (getHBInfo, PaymentKit.toXml (params), certPath, partner);}
Specific implementation of encapsulation com.javen.utils.ReadPackUtils.java
/ * * query red packets according to merchant order number * @ param mch_billno merchant order number * @ param partner merchant number * @ param wxappid public account ID * @ param paternerKey merchant signature Key * @ param certPath certificate path * @ return * / public static String query (String mch_billno,String partner,String wxappid,String paternerKey,String certPath) {Map params = new HashMap () / / Random string params.put ("nonce_str", System.currentTimeMillis () / 1000 + ""); / / merchant order number params.put ("mch_billno", mch_billno); / / merchant number params.put ("mch_id", partner); / / Public account ID params.put ("appid", wxappid) Params.put ("bill_type", "MCHT"); / / create signature String sign = PaymentKit.createSign (params, paternerKey); params.put ("sign", sign); String xmlResult = RedPackApi.getHbInfo (params, certPath, partner); Map result = PaymentKit.xmlToMap (xmlResult); System.out.println (result); return JsonKit.toJson (result);} Thank you for reading! This is the end of the article on "example analysis of cash red packets developed by Wechat official account". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.