{"id":29634,"date":"2024-11-25T10:34:10","date_gmt":"2024-11-25T02:34:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29634\/"},"modified":"2024-11-25T10:34:10","modified_gmt":"2024-11-25T02:34:10","slug":"%e5%be%ae%e4%bf%a1%e6%89%ab%e7%a0%81%e6%94%af%e4%bb%98%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29634\/","title":{"rendered":"\u5fae\u4fe1\u626b\u7801\u652f\u4ed8\u6a21\u5f0f"},"content":{"rendered":"<h1>\u5fae\u4fe1\u626b\u7801\u652f\u4ed8(\u6a21\u5f0f\u4e00)<\/h1>\n<blockquote><p>\n  \u5fae\u4fe1\u626b\u7801\u652f\u4ed8\u9047\u5230\u7684\u95ee\u9898\n<\/p><\/blockquote>\n<ul>\n<li>\n<p>\u539f\u751f\u652f\u4ed8URL\u53c2\u6570\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>\u56de\u8c03URL\u6709\u56de\u8c03\uff0c\u4f46\u662f\u63a5\u6536\u4e0d\u5230\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u5546\u6237\u540e\u53f0\u8fd4\u56de\u7684\u6570\u636e\u5b57\u6bb5\u7ed3\u6784\u4e0d\u5408\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u83b7\u53d6\u5546\u6237\u8ba2\u5355\u4fe1\u606f\u8d85\u65f6\u6216\u8005\u5546\u6237\u8fd4\u56de\u7684httpcode\u975e200<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u89e3\u51b3\u95ee\u9898<\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>\u539f\u751f\u652f\u4ed8URL\u53c2\u6570\u9519\u8bef<br \/>\u8fd9\u4e2a\u9519\u8bef\u4e00\u822c\u4f1a\u51fa\u73b0\u5728\u83b7\u53d6\u5230\u4e8c\u7ef4\u7801URL\u4e4b\u540e\u751f\u6210\u4e8c\u7ef4\u7801\u5fae\u4fe1\u626b\u7801\u7684\u65f6\u5019\u3002\u5982\u679c\u4f60\u51fa\u73b0\u6b64\u7c7b\u578b\u7684\u95ee\u9898\u8bf7\u68c0\u67e5<\/p>\n<\/li>\n<\/ul>\n<p>1\u3001\u751f\u6210\u4e8c\u7ef4\u7801\u6240\u9700\u53c2\u6570\u5217\u8868\u4e2d\u53c2\u6570\u662f\u5426\u6709\u9519\u8bef\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09<br \/>2\u3001\u53c2\u6570\u4e2d\u7b7e\u540dsign\u65f6\u5019\u6b63\u786e \u7b7e\u540d\u7b97\u6cd5 &nbsp; \u7b7e\u540d\u6821\u9a8c\u5de5\u5177<\/p>\n<hr>\n<blockquote>\n<p>\u4ee5\u4e0b\u662f\u751f\u6210\u4e8c\u7ef4\u7801URL\u7684\u4ee3\u7801<\/p>\n<\/blockquote>\n<pre>\/**\r\n * \r\n * @author Javen\r\n * 2016\u5e745\u670814\u65e5\r\n * \u626b\u7801\u652f\u4ed8\u83b7\u53d6\u4e8c\u7ef4\u7801URL\uff08\u6a21\u5f0f\u4e00\uff09\r\n *\/\r\npublic String getCodeUrl(){\r\n    String url=\"weixin:\/\/wxpay\/bizpayurl?sign=XXXXX&amp;appid=XXXXX&amp;mch_id=XXXXX&amp;product_id=XXXXX&amp;time_stamp=XXXXX&amp;nonce_str=XXXXX\";\r\n    String product_id=\"001\";\r\n    String timeStamp=Long.toString(System.currentTimeMillis() \/ 1000);\r\n    String nonceStr=Long.toString(System.currentTimeMillis());\r\n    Map&lt;String, String&gt; packageParams = new HashMap&lt;String, String&gt;();\r\n    packageParams.put(\"appid\", appid);\r\n    packageParams.put(\"mch_id\", partner);\r\n    packageParams.put(\"product_id\",product_id);\r\n    packageParams.put(\"time_stamp\", timeStamp);\r\n    packageParams.put(\"nonce_str\", nonceStr);\r\n    String packageSign = PaymentKit.createSign(packageParams, paternerKey);\r\n    return StringUtils.replace(url, \"XXXXX\", packageSign,appid,partner,product_id,timeStamp,nonceStr);\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\n<p>\u56de\u8c03\u63a5\u53e3URL\u6709\u56de\u8c03\uff0c\u4f46\u662f\u63a5\u6536\u4e0d\u5230\u53c2\u6570<\/p>\n<p>Enumeration &nbsp;en=getParaNames(); <\/p>\n<pre>  while (en.hasMoreElements()) {\r\n      Object o= en.nextElement();\r\n      System.out.println(o.toString()+\"=\"+getPara(o.toString()));\r\n  }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4e2d\u8f93\u51fa\u7684\u53c2\u6570\u90fd\u4e3a<\/p>\n<p>\u7531\u4e8e\u5b98\u65b9\u7684\u6587\u6863\u63cf\u8ff0\u4e0d\u662f\u5f88\u6e05\u695a\uff0c\u5927\u5bb6\u90fd\u4ee5\u4e3a\u56de\u8c03\u8bf7\u6c42\u5c06\u5e26productid\u548c\u7528\u6237\u7684openid\u7b49\u53c2\u6570\u662f\u4ee5\u666e\u901a\u7684\u53c2\u6570\u4e00\u6837\uff0c\u5176\u5b9e\u8fd9\u4e2a\u56de\u8c03\u8fd4\u56de\u7684\u53c2\u6570\u662f\u4e00\u4e2a\u8f93\u5165\u6d41<\/p>\n<pre>HttpServletRequest request = getRequest();\r\n         \/**\r\n         * \u83b7\u53d6\u7528\u6237\u626b\u63cf\u4e8c\u7ef4\u7801\u540e\uff0c\u5fae\u4fe1\u8fd4\u56de\u7684\u4fe1\u606f\r\n         *\/\r\n        InputStream inStream = request.getInputStream();\r\n        ByteArrayOutputStream outSteam = new ByteArrayOutputStream();\r\n        byte[] buffer = new byte[1024];\r\n        int len = 0;\r\n        while ((len = inStream.read(buffer)) != -1) {\r\n            outSteam.write(buffer, 0, len);\r\n        }\r\n        outSteam.close();\r\n        inStream.close();\r\n        String result  = new String(outSteam.toByteArray(),\"utf-8\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>result\u7ed3\u679c\u4e3a<\/p>\n<\/p>\n<p> &lt;\/prepay_id&gt;&lt;br&gt;&lt;trade_type&gt;&lt;\/trade_type&gt;&lt;br&gt;&lt;code_url&gt;![CDATA[weixin:\/\/wxpay\/bizpayurl?pr=Gj3ZF2b]]&lt;\/code_url&gt;&lt;br&gt;&lt;\/xml&gt;&lt;\/p&gt; &lt;p&gt;\u5982\u679c\u8fd4\u56de\u7684 return_code &nbsp;result_code \u4e0d\u4e3aSUCCESS \u800c\u56de\u8c03\u7684\u63a5\u53e3\u6ca1\u6709\u8fd4\u56de\u4efb\u4f55\u6570\u636e\u6216\u8005\u8fd4\u56de\u7684\u6570\u636e\u4e0d\u5408\u6cd5\u5c31\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u9519\u8bef&lt;\/p&gt; &lt;ul class=&#8221; list-paddingleft-2&#8243;&gt; &lt;li&gt;&lt;p&gt;\u5546\u6237\u540e\u53f0\u8fd4\u56de\u7684\u6570\u636e\u5b57\u6bb5\u7ed3\u6784\u4e0d\u5408\u6cd5\uff08\u8fd4\u56de\u7684\u6570\u636e\u5305\u683c\u5f0f\u4e0d\u6b63\u786e\uff09&lt;\/p&gt;&lt;\/li&gt; &lt;li&gt;&lt;p&gt;\u83b7\u53d6\u5546\u6237\u8ba2\u5355\u4fe1\u606f\u8d85\u65f6\u6216\u8005\u5546\u6237\u8fd4\u56de\u7684httpcode\u975e200\uff08\u6ca1\u6709\u8fd4\u56de\u7684\u6570\u636e\u5305\uff09&lt;\/p&gt;&lt;\/li&gt; &lt;\/ul&gt; &lt;p&gt;\u5982\u679c\u4ee5\u4e0a\u90fd\u6ca1\u6709\u95ee\u9898\uff0c\u5c31\u5269\u4e0b\u6700\u540e\u4e00\u4e2a\u6b65\u9aa4\u4e86 &nbsp;\u5546\u6237\u540e\u53f0\u7cfb\u7edf\u5c06prepay_id\u8fd4\u56de\u7ed9\u5fae\u4fe1\u652f\u4ed8\u7cfb\u7edf &nbsp;\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u4ee3\u7801&lt;\/p&gt;&lt;pre class=&#8221;brush:php;toolbar:false&#8221;&gt;\/** * @author Javen * 2016\u5e745\u670814\u65e5 * \u626b\u7801\u652f\u4ed8\u56de\u8c03\uff08\u6a21\u5f0f\u4e00\uff09 *\/ \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>public void wxpay(){<br \/> &nbsp; &nbsp; &nbsp; &nbsp;try {<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpServletRequest request = getRequest();<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/**<\/p>\n<pre>         * \u83b7\u53d6\u7528\u6237\u626b\u63cf\u4e8c\u7ef4\u7801\u540e\uff0c\u5fae\u4fe1\u8fd4\u56de\u7684\u4fe1\u606f\r\n         *\/\r\n        InputStream inStream = request.getInputStream();\r\n        ByteArrayOutputStream outSteam = new ByteArrayOutputStream();\r\n        byte[] buffer = new byte[1024];\r\n        int len = 0;\r\n        while ((len = inStream.read(buffer)) != -1) {\r\n            outSteam.write(buffer, 0, len);\r\n        }\r\n        outSteam.close();\r\n        inStream.close();\r\n        String result  = new String(outSteam.toByteArray(),\"utf-8\");\r\n\r\n        System.out.println(\"callback&gt;&gt;&gt;&gt;\"+result);\r\n        \/**\r\n         * \u83b7\u53d6\u8fd4\u56de\u7684\u4fe1\u606f\u5185\u5bb9\u4e2d\u5404\u4e2a\u53c2\u6570\u7684\u503c\r\n         *\/\r\n        Map&lt;String, String&gt; map = PaymentKit.xmlToMap(result);\r\n        for (String key : map.keySet()) {\r\n               System.out.println(\"key= \"+ key + \" and value= \" + map.get(key));\r\n        }\r\n\r\n        String appid=map.get(\"appid\");\r\n        String openid = map.get(\"openid\");\r\n        String mch_id = map.get(\"mch_id\");\r\n        String is_subscribe = map.get(\"is_subscribe\");\r\n        String nonce_str = map.get(\"nonce_str\");\r\n        String product_id = map.get(\"product_id\");\r\n        String sign = map.get(\"sign\");\r\n        Map&lt;String, String&gt; packageParams = new HashMap&lt;String, String&gt;();\r\n        packageParams.put(\"appid\", appid);\r\n        packageParams.put(\"openid\", openid);\r\n        packageParams.put(\"mch_id\",mch_id);\r\n        packageParams.put(\"is_subscribe\",is_subscribe);\r\n        packageParams.put(\"nonce_str\",nonce_str);\r\n        packageParams.put(\"product_id\", product_id);\r\n\r\n        String packageSign = PaymentKit.createSign(packageParams, paternerKey);\r\n        \/\/ \u7edf\u4e00\u4e0b\u5355\u6587\u6863\u5730\u5740\uff1ahttps:\/\/pay.weixin.qq.com\/wiki\/doc\/api\/jsapi.php?chapter=9_1\r\n\r\n        Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();\r\n        params.put(\"appid\", appid);\r\n        params.put(\"mch_id\", mch_id);\r\n        params.put(\"body\", \"\u6d4b\u8bd5\u626b\u7801\u652f\u4ed8\");\r\n        String out_trade_no=Long.toString(System.currentTimeMillis());\r\n        params.put(\"out_trade_no\", out_trade_no);\r\n        int price=((int)(Float.valueOf(10)*100));\r\n        params.put(\"total_fee\", price+\"\");\r\n        params.put(\"attach\", out_trade_no);\r\n\r\n        String ip = IpKit.getRealIp(getRequest());\r\n        if (StrKit.isBlank(ip)) {\r\n            ip = \"127.0.0.1\";\r\n        }\r\n\r\n        params.put(\"spbill_create_ip\", ip);\r\n        params.put(\"trade_type\", TradeType.NATIVE.name());\r\n        params.put(\"nonce_str\", System.currentTimeMillis() \/ 1000 + \"\");\r\n        params.put(\"notify_url\", notify_url);\r\n        params.put(\"openid\", openid);\r\n\r\n        String paysign = PaymentKit.createSign(params, paternerKey);\r\n        params.put(\"sign\", paysign);\r\n\r\n        String xmlResult = PaymentApi.pushOrder(params);\r\n\r\n        System.out.println(\"prepay_xml&gt;&gt;&gt;\"+xmlResult);\r\n\r\n        \/**\r\n         * \u53d1\u9001\u4fe1\u606f\u7ed9\u5fae\u4fe1\u670d\u52a1\u5668\r\n         *\/\r\n        Map&lt;String, String&gt; payResult = PaymentKit.xmlToMap(xmlResult);\r\n\r\n        String return_code = payResult.get(\"return_code\");\r\n        String result_code = payResult.get(\"result_code\");\r\n\r\n        if (StrKit.notBlank(return_code) &amp;&amp; StrKit.notBlank(result_code) &amp;&amp; return_code.equalsIgnoreCase(\"SUCCESS\")&amp;&amp;result_code.equalsIgnoreCase(\"SUCCESS\")) {\r\n            \/\/ \u4ee5\u4e0b\u5b57\u6bb5\u5728return_code \u548cresult_code\u90fd\u4e3aSUCCESS\u7684\u65f6\u5019\u6709\u8fd4\u56de\r\n            String prepay_id = payResult.get(\"prepay_id\");\r\n\r\n            Map&lt;String, String&gt; prepayParams = new HashMap&lt;String, String&gt;();\r\n            prepayParams.put(\"return_code\", \"SUCCESS\");\r\n            prepayParams.put(\"appId\", appid);\r\n            prepayParams.put(\"mch_id\", mch_id);\r\n            prepayParams.put(\"nonceStr\", System.currentTimeMillis() + \"\");\r\n            prepayParams.put(\"prepay_id\", prepay_id);\r\n            String prepaySign = null;\r\n            if (sign.equals(packageSign)) {\r\n                prepayParams.put(\"result_code\", \"SUCCESS\");\r\n            }else {\r\n                prepayParams.put(\"result_code\", \"FAIL\");\r\n                prepayParams.put(\"err_code_des\", \"\u8ba2\u5355\u5931\u6548\");   \/\/result_code\u4e3aFAIL\u65f6\uff0c\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\uff0cvalue\u503c\u662f\u5fae\u4fe1\u544a\u8bc9\u5ba2\u6237\u7684\u4fe1\u606f\r\n            }\r\n            prepaySign = PaymentKit.createSign(prepayParams, paternerKey);\r\n            prepayParams.put(\"sign\", prepaySign);\r\n            String xml = PaymentKit.toXml(prepayParams);\r\n            log.error(xml);\r\n            renderText(xml);\r\n        }\r\n    } catch (UnsupportedEncodingException e) {\r\n        \/\/ TODO Auto-generated catch block\r\n        e.printStackTrace();\r\n    } catch (IOException e) {\r\n        \/\/ TODO Auto-generated catch block\r\n        e.printStackTrace();\r\n    }\r\n\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u626b\u7801\u652f\u4ed8\u6a21\u5f0f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5fae\u4fe1\u626b\u7801\u652f\u4ed8(\u6a21\u5f0f\u4e00) \u5fae\u4fe1\u626b\u7801\u652f\u4ed8\u9047\u5230\u7684\u95ee\u9898 \u539f\u751f\u652f\u4ed8URL\u53c2\u6570\u9519\u8bef \u56de\u8c03URL\u6709\u56de\u8c03\uff0c\u4f46\u662f\u63a5\u6536\u4e0d\u5230\u53c2\u6570 \u5546\u6237\u540e\u53f0\u8fd4\u56de\u7684\u6570\u636e\u5b57\u6bb5\u7ed3\u6784\u4e0d\u5408\u6cd5 \u83b7\u53d6\u5546\u6237\u8ba2\u5355\u4fe1\u606f\u8d85\u65f6\u6216\u8005\u5546\u6237\u8fd4\u56de\u7684httpcode\u975e200 \u89e3\u51b3\u95ee\u9898 \u539f\u751f\u652f\u4ed8URL\u53c2\u6570\u9519\u8bef\u8fd9\u4e2a\u9519\u8bef\u4e00\u822c\u4f1a\u51fa\u73b0\u5728\u83b7\u53d6\u5230\u4e8c\u7ef4\u7801URL\u4e4b\u540e\u751f\u6210\u4e8c\u7ef4\u7801\u5fae\u4fe1\u626b\u7801\u7684\u65f6\u5019\u3002\u5982\u679c\u4f60\u51fa\u73b0\u6b64\u7c7b\u578b\u7684\u95ee\u9898\u8bf7\u68c0\u67e5 1\u3001\u751f\u6210\u4e8c\u7ef4\u7801\u6240\u9700\u53c2\u6570\u5217\u8868\u4e2d\u53c2\u6570\u662f\u5426\u6709\u9519\u8bef\uff08\u533a\u5206\u5927\u5c0f\u5199\uff092\u3001\u53c2\u6570\u4e2d\u7b7e\u540dsign\u65f6\u5019\u6b63\u786e \u7b7e\u540d\u7b97\u6cd5 &nbsp; \u7b7e\u540d\u6821\u9a8c\u5de5\u5177 \u4ee5\u4e0b\u662f\u751f\u6210\u4e8c\u7ef4\u7801URL\u7684\u4ee3\u7801 \/** * * @author Javen * 2016\u5e745\u670814\u65e5 * \u626b\u7801\u652f\u4ed8\u83b7\u53d6\u4e8c\u7ef4\u7801URL\uff08\u6a21\u5f0f\u4e00\uff09 *\/ public String getCodeUrl(){ String url=&#8221;weixin:\/\/wxpay\/bizpayurl?sign=XXXXX&amp;appid=XXXXX&amp;mch_id=XXXXX&amp;product_id=XXXXX&amp;time_stamp=XXXXX&amp;nonce_str=XXXXX&#8221;; String product_id=&#8221;001&#8243;; String timeStamp=Long.toString(System.currentTimeMillis() \/ 1000); String nonceStr=Long.toString(System.currentTimeMillis()); Map&lt;String, String&gt; packageParams = new HashMap&lt;String, String&gt;(); packageParams.put(&#8220;appid&#8221;, appid); packageParams.put(&#8220;mch_id&#8221;, partner); packageParams.put(&#8220;product_id&#8221;,product_id); packageParams.put(&#8220;time_stamp&#8221;, timeStamp); packageParams.put(&#8220;nonce_str&#8221;, nonceStr); String packageSign = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-29634","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=29634"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29634\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}