1. <sup id="2vpzx"></sup>
      刷卡支付測(cè)試<\/body>\r\n   1000<\/device_info>\r\n   <\/goods_tag>\r\n   10000100<\/mch_id>\r\n   8aaee146b1dee7cec9100add9b96cbe2<\/nonce_str>\r\n   1415757673<\/out_trade_no>\r\n   14.17.22.52<\/spbill_create_ip>\r\n   <\/time_expire>\r\n   1<\/total_fee>\r\n   C29DB7DB1FD4136B84AE35604756362C<\/sign>\r\n<\/xml><\/pre>

      Note: Parameter values ??can be escaped with XML, The CDATA tag is used to indicate that the data is not parsed by the XML parser. <\/p>

      Return results<\/h3>

      Name variable name required type example value description<\/p>

      #Return Status CodeReturn information

      <sup id="rt3hz"><tfoot id="rt3hz"></tfoot></sup>

    2. <ruby id="rt3hz"><rp id="rt3hz"><delect id="rt3hz"></delect></rp></ruby><abbr id="rt3hz"></abbr>
      <\/td><\/td><\/td><\/td><\/td><\/td><\/tr>
      <\/td>return_code<\/td> is<\/td>String(16)<\/td>SUCCESS<\/td>SUCCESS\/FAIL This field is the communication identification. Non-transaction identifier. You need to check the result_code to determine whether the transaction is successful.<\/td><\/tr>
      <\/td>return_msg<\/td>No<\/td>String(128) <\/td>Signature failed<\/td>Return information, if not empty, is the error reason Signature failed Parameter format verification error<\/td><\/tr><\/tbody>

      當(dāng)return_code為SUCCESS的時(shí)候,還會(huì)包括以下字段:<\/p>

      名稱 變量名 必填 類型 示例值 描述<\/p>

    3. <\/td><\/td><\/td><\/td><\/td><\/td><\/tr>
      公眾賬號(hào)ID<\/td>appid<\/td>是<\/td>String(32)<\/td>wx8888888888888888<\/td>調(diào)用接口提交的公眾賬號(hào)ID<\/td><\/tr>
      商戶號(hào)<\/td>mch_id<\/td>是<\/td>String(32)<\/td>1900000109<\/td>調(diào)用接口提交的商戶號(hào)<\/td><\/tr>
      設(shè)備號(hào)<\/td>device_info<\/td>否<\/td>String(32)<\/td>013467007045764<\/td>調(diào)用接口提交的終端設(shè)備號(hào),<\/td><\/tr>
      隨機(jī)字符串<\/td>nonce_str<\/td>是<\/td>String(32)<\/td>5K8264ILTKCH16CQ2502SI8ZNMTM67VS<\/td>微信返回的隨機(jī)字符串<\/td><\/tr>
      簽名<\/td>sign<\/td>是<\/td>String(32)<\/td>C380BEC2BFD727A4B6845133519F3AD6<\/td>微信返回的簽名,詳見簽名生成算法<\/td><\/tr>
      業(yè)務(wù)結(jié)果<\/td>result_code<\/td>是<\/td>String(16)<\/td>SUCCESS<\/td>SUCCESS\/FAIL<\/td><\/tr>
      錯(cuò)誤代碼<\/td>err_code<\/td>否<\/td>String(32)<\/td>SYSTEMERROR<\/td>詳細(xì)參見錯(cuò)誤列表<\/td><\/tr>
      錯(cuò)誤代碼描述<\/td>err_code_des<\/td>否<\/td>String(128)<\/td>系統(tǒng)錯(cuò)誤<\/td>錯(cuò)誤返回的信息描述<\/td><\/tr><\/tbody><\/table>

      當(dāng)return_code 和result_code都為SUCCESS的時(shí),還會(huì)包括以下字段:<\/p>

      名稱 變量名 必填 類型 示例值 描述<\/p>

      <style id="rt3hz"></style>
        <\/td><\/td><\/td><\/td><\/td><\/td><\/tr>
        用戶標(biāo)識(shí)<\/td>openid<\/td>是<\/td>String(128)<\/td>Y<\/td>用戶在商戶appid 下的唯一標(biāo)識(shí)<\/td><\/tr>
        是否關(guān)注公眾賬號(hào)<\/td>is_subscribe<\/td>是<\/td>String(1)<\/td>Y<\/td>用戶是否關(guān)注公眾賬號(hào),僅在公眾賬號(hào)類型支付有效,取值范圍:Y或N;Y-關(guān)注;N-未關(guān)注<\/td><\/tr>
        交易類型<\/td>trade_type<\/td>是<\/td>String(16)<\/td>MICROPAY<\/td>支付類型為MICROPAY(即掃碼支付)<\/td><\/tr>
        付款銀行<\/td>bank_type<\/td>是<\/td>String(16)<\/td>CMC<\/td>銀行類型,采用字符串類型的銀行標(biāo)識(shí),值列表詳見銀行類型<\/td><\/tr>
        貨幣類型<\/td>fee_type<\/td>否<\/td>String(16)<\/td>CNY<\/td>符合ISO 4217標(biāo)準(zhǔn)的三位字母代碼,默認(rèn)人民幣:CNY,其他值列表詳見貨幣類型<\/td><\/tr>
        訂單金額<\/td>total_fee<\/td>是<\/td>Int<\/td>888<\/td>訂單總金額,單位為分,只能為整數(shù),詳見支付金額<\/td><\/tr>
        現(xiàn)金支付貨幣類型<\/td>cash_fee_type<\/td>否<\/td>String(16)<\/td>CNY<\/td>符合ISO 4217標(biāo)準(zhǔn)的三位字母代碼,默認(rèn)人民幣:CNY,其他值列表詳見貨幣類型<\/td><\/tr>
        現(xiàn)金支付金額<\/td>cash_fee<\/td>是<\/td>Int<\/td>100<\/td>訂單現(xiàn)金支付金額,詳見支付金額<\/td><\/tr>
        微信支付訂單號(hào)<\/td>transaction_id<\/td>是<\/td>String(32)<\/td>1217752501201407033233368018<\/td>微信支付訂單號(hào)<\/td><\/tr>
        商戶訂單號(hào)<\/td>out_trade_no<\/td>是<\/td>String(32)<\/td>1217752501201407033233368018<\/td>商戶系統(tǒng)的訂單號(hào),與請(qǐng)求一致。<\/td><\/tr>
        商家數(shù)據(jù)包<\/td>attach<\/td>否<\/td>String(128)<\/td>123456<\/td>商家數(shù)據(jù)包,原樣返回<\/td><\/tr>
        支付完成時(shí)間<\/td>time_end<\/td>是<\/td>String(14)<\/td>20141030133525<\/td>訂單生成時(shí)間,格式為yyyyMMddHHmmss,如2009年12月25日9點(diǎn)10分10秒表示為20091225091010。詳見時(shí)間規(guī)則<\/td><\/tr><\/tbody><\/table>

        舉例如下:<\/p>

        \r\n   <\/return_code>\r\n   <\/return_msg>\r\n   <\/appid>\r\n   <\/mch_id>\r\n   <\/device_info>\r\n   <\/nonce_str>\r\n   <\/sign>\r\n   <\/result_code>\r\n   <\/openid>\r\n   <\/is_subscribe>\r\n   <\/trade_type>\r\n   <\/bank_type>\r\n   1<\/total_fee>\r\n   0<\/coupon_fee>\r\n   <\/fee_type>\r\n   <\/transaction_id>\r\n   <\/out_trade_no>\r\n   <\/attach>\r\n   <\/time_end>\r\n<\/xml><\/pre>

        二、刷卡支付類實(shí)現(xiàn)<\/h2>

        在微信支付原來(lái)的微信支付類文件中,仿照統(tǒng)一支付類的方式,添加刷卡支付類如下:<\/p>

        \/**\r\n * 刷卡支付接口類\r\n *\/\r\nclass MicroPay_pub extends Wxpay_client_pub\r\n{    \r\n    function __construct() \r\n    {\r\n        \/\/設(shè)置接口鏈接\r\n        $this->url = \"https:\/\/api.mch.weixin.qq.com\/pay\/micropay\";\r\n        \/\/設(shè)置curl超時(shí)時(shí)間\r\n        $this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;\r\n    }\r\n    \r\n    \/**\r\n     * 生成接口參數(shù)xml\r\n     *\/\r\n    function createXml()\r\n    {\r\n        try\r\n        {\r\n            \/\/檢測(cè)必填參數(shù)\r\n            if($this->parameters[\"out_trade_no\"] == null){\r\n                throw new SDKRuntimeException(\"缺少統(tǒng)一支付接口必填參數(shù)out_trade_no!\".\"
        \");\r\n            }elseif($this->parameters[\"body\"] == null){\r\n                throw new SDKRuntimeException(\"缺少統(tǒng)一支付接口必填參數(shù)body!\".\"
        \");\r\n            }elseif ($this->parameters[\"total_fee\"] == null ) {\r\n                throw new SDKRuntimeException(\"缺少統(tǒng)一支付接口必填參數(shù)total_fee!\".\"
        \");\r\n            }elseif ($this->parameters[\"auth_code\"] == null) {\r\n                throw new SDKRuntimeException(\"缺少統(tǒng)一支付接口必填參數(shù)auth_code!\".\"
        \");\r\n            }\r\n               $this->parameters[\"appid\"] = WxPayConf_pub::APPID;\/\/公眾賬號(hào)ID\r\n               $this->parameters[\"mch_id\"] = WxPayConf_pub::MCHID;\/\/商戶號(hào)\r\n               $this->parameters[\"spbill_create_ip\"] = $_SERVER['REMOTE_ADDR'];\/\/終端ip        \r\n            $this->parameters[\"nonce_str\"] = $this->createNoncestr();\/\/隨機(jī)字符串\r\n            $this->parameters[\"sign\"] = $this->getSign($this->parameters);\/\/簽名\r\n            \/\/ var_dump($this->parameters);\r\n            return  $this->arrayToXml($this->parameters);\r\n        }catch (SDKRuntimeException $e)\r\n        {\r\n            die($e->errorMessage());\r\n        }\r\n    }\r\n}<\/pre>

        原有的基礎(chǔ)類和請(qǐng)求類也列出如下:<\/p>

        \/**\r\n * 所有接口的基類\r\n *\/\r\nclass Common_util_pub\r\n{\r\n    function __construct() {\r\n    }\r\n\r\n    function trimString($value)\r\n    {\r\n        $ret = null;\r\n        if (null != $value) \r\n        {\r\n            $ret = $value;\r\n            if (strlen($ret) == 0) \r\n            {\r\n                $ret = null;\r\n            }\r\n        }\r\n        return $ret;\r\n    }\r\n    \r\n    \/**\r\n     *     作用:產(chǎn)生隨機(jī)字符串,不長(zhǎng)于32位\r\n     *\/\r\n    public function createNoncestr( $length = 32 ) \r\n    {\r\n        $chars = \"abcdefghijklmnopqrstuvwxyz0123456789\";  \r\n        $str =\"\";\r\n        for ( $i = 0; $i < $length; $i++ )  {  \r\n            $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);  \r\n        }  \r\n        return $str;\r\n    }\r\n    \r\n    \/**\r\n     *     作用:格式化參數(shù),簽名過(guò)程需要使用\r\n     *\/\r\n    function formatBizQueryParaMap($paraMap, $urlencode)\r\n    {\r\n        $buff = \"\";\r\n        ksort($paraMap);\r\n        foreach ($paraMap as $k => $v)\r\n        {\r\n            if($urlencode)\r\n            {\r\n               $v = urlencode($v);\r\n            }\r\n            \/\/$buff .= strtolower($k) . \"=\" . $v . \"&\";\r\n            $buff .= $k . \"=\" . $v . \"&\";\r\n        }\r\n        $reqPar;\r\n        if (strlen($buff) > 0) \r\n        {\r\n            $reqPar = substr($buff, 0, strlen($buff)-1);\r\n        }\r\n        return $reqPar;\r\n    }\r\n    \r\n    \/**\r\n     *     作用:生成簽名\r\n     *\/\r\n    public function getSign($Obj)\r\n    {\r\n        foreach ($Obj as $k => $v)\r\n        {\r\n            $Parameters[$k] = $v;\r\n        }\r\n        \/\/簽名步驟一:按字典序排序參數(shù)\r\n        ksort($Parameters);\r\n        $String = $this->formatBizQueryParaMap($Parameters, false);\r\n        \/\/echo '【string1】'.$String.'<\/br>';\r\n        \/\/簽名步驟二:在string后加入KEY\r\n        $String = $String.\"&key=\".WxPayConf_pub::KEY;\r\n        \/\/echo \"【string2】\".$String.\"<\/br>\";\r\n        \/\/簽名步驟三:MD5加密\r\n        $String = md5($String);\r\n        \/\/echo \"【string3】 \".$String.\"<\/br>\";\r\n        \/\/簽名步驟四:所有字符轉(zhuǎn)為大寫\r\n        $result_ = strtoupper($String);\r\n        \/\/echo \"【result】 \".$result_.\"<\/br>\";\r\n        return $result_;\r\n    }\r\n    \r\n    \/**\r\n     *     作用:array轉(zhuǎn)xml\r\n     *\/\r\n    function arrayToXml($arr)\r\n    {\r\n        $xml = \"\";\r\n        foreach ($arr as $key=>$val)\r\n        {\r\n             if (is_numeric($val))\r\n             {\r\n                 $xml.=\"<\".$key.\">\".$val.\"<\/\".$key.\">\"; \r\n\r\n             }\r\n             else\r\n                 $xml.=\"<\".$key.\"><\/\".$key.\">\";  \r\n        }\r\n        $xml.=\"<\/xml>\";\r\n        return $xml; \r\n    }\r\n    \r\n    \/**\r\n     *     作用:將xml轉(zhuǎn)為array\r\n     *\/\r\n    public function xmlToArray($xml)\r\n    {        \r\n        \/\/將XML轉(zhuǎn)為array        \r\n        $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);        \r\n        return $array_data;\r\n    }\r\n\r\n    \/**\r\n     *     作用:以post方式提交xml到對(duì)應(yīng)的接口url\r\n     *\/\r\n    public function postXmlCurl($xml,$url,$second=30)\r\n    {        \r\n        \/\/初始化curl        \r\n           $ch = curl_init();\r\n        \/\/設(shè)置超時(shí)\r\n        curl_setopt($ch, CURLOP_TIMEOUT, $second);\r\n        \/\/這里設(shè)置代理,如果有的話\r\n        \/\/curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');\r\n        \/\/curl_setopt($ch,CURLOPT_PROXYPORT, 8080);\r\n        curl_setopt($ch,CURLOPT_URL, $url);\r\n        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);\r\n        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);\r\n        \/\/設(shè)置header\r\n        curl_setopt($ch, CURLOPT_HEADER, FALSE);\r\n        \/\/要求結(jié)果為字符串且輸出到屏幕上\r\n        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);\r\n        \/\/post提交方式\r\n        curl_setopt($ch, CURLOPT_POST, TRUE);\r\n        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);\r\n        \/\/運(yùn)行curl\r\n        $data = curl_exec($ch);\r\n        curl_close($ch);\r\n        \/\/返回結(jié)果\r\n        if($data)\r\n        {\r\n            curl_close($ch);\r\n            return $data;\r\n        }\r\n        else \r\n        { \r\n            $error = curl_errno($ch);\r\n            echo \"curl出錯(cuò),錯(cuò)誤碼:$error\".\"
        \"; \r\n            echo \"錯(cuò)誤原因查詢<\/a><\/br>\";\r\n            curl_close($ch);\r\n            return false;\r\n        }\r\n    }\r\n\r\n    \/**\r\n     *     作用:使用證書,以post方式提交xml到對(duì)應(yīng)的接口url\r\n     *\/\r\n    function postXmlSSLCurl($xml,$url,$second=30)\r\n    {\r\n        $ch = curl_init();\r\n        \/\/超時(shí)時(shí)間\r\n        curl_setopt($ch,CURLOPT_TIMEOUT,$second);\r\n        \/\/這里設(shè)置代理,如果有的話\r\n        \/\/curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');\r\n        \/\/curl_setopt($ch,CURLOPT_PROXYPORT, 8080);\r\n        curl_setopt($ch,CURLOPT_URL, $url);\r\n        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);\r\n        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);\r\n        \/\/設(shè)置header\r\n        curl_setopt($ch,CURLOPT_HEADER,FALSE);\r\n        \/\/要求結(jié)果為字符串且輸出到屏幕上\r\n        curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);\r\n        \/\/設(shè)置證書\r\n        \/\/使用證書:cert 與 key 分別屬于兩個(gè).pem文件\r\n        \/\/默認(rèn)格式為PEM,可以注釋\r\n        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');\r\n        curl_setopt($ch,CURLOPT_SSLCERT, dirname(__FILE__).WxPayConf_pub::SSLCERT_PATH);\r\n        \/\/默認(rèn)格式為PEM,可以注釋\r\n        curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');\r\n        curl_setopt($ch,CURLOPT_SSLKEY, dirname(__FILE__).WxPayConf_pub::SSLKEY_PATH);\r\n        \/\/post提交方式\r\n        curl_setopt($ch,CURLOPT_POST, true);\r\n        curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);\r\n        $data = curl_exec($ch);\r\n        \/\/返回結(jié)果\r\n        if($data){\r\n            curl_close($ch);\r\n            return $data;\r\n        }\r\n        else { \r\n            $error = curl_errno($ch);\r\n            echo \"curl出錯(cuò),錯(cuò)誤碼:$error\".\"
        \"; \r\n            echo \"錯(cuò)誤原因查詢<\/a><\/br>\";\r\n            curl_close($ch);\r\n            return false;\r\n        }\r\n    }\r\n    \r\n    \/**\r\n     *     作用:打印數(shù)組\r\n     *\/\r\n    function printErr($wording='',$err='')\r\n    {\r\n        print_r('
        ');\r\n        echo $wording.\"<\/br>\";\r\n        var_dump($err);\r\n        print_r('<\/pre>');\r\n    }\r\n}\r\n\r\n\/**\r\n * 請(qǐng)求型接口的基類\r\n *\/\r\nclass Wxpay_client_pub extends Common_util_pub \r\n{\r\n    var $parameters;\/\/請(qǐng)求參數(shù),類型為關(guān)聯(lián)數(shù)組\r\n    public $response;\/\/微信返回的響應(yīng)\r\n    public $result;\/\/返回參數(shù),類型為關(guān)聯(lián)數(shù)組\r\n    var $url;\/\/接口鏈接\r\n    var $curl_timeout;\/\/curl超時(shí)時(shí)間\r\n    \r\n    \/**\r\n     *     作用:設(shè)置請(qǐng)求參數(shù)\r\n     *\/\r\n    function setParameter($parameter, $parameterValue)\r\n    {\r\n        $this->parameters[$this->trimString($parameter)] = $this->trimString($parameterValue);\r\n    }\r\n    \r\n    \/**\r\n     *     作用:設(shè)置標(biāo)配的請(qǐng)求參數(shù),生成簽名,生成接口參數(shù)xml\r\n     *\/\r\n    function createXml()\r\n    {\r\n           $this->parameters[\"appid\"] = WxPayConf_pub::APPID;\/\/公眾賬號(hào)ID\r\n           $this->parameters[\"mch_id\"] = WxPayConf_pub::MCHID;\/\/商戶號(hào)\r\n        $this->parameters[\"nonce_str\"] = $this->createNoncestr();\/\/隨機(jī)字符串\r\n        $this->parameters[\"sign\"] = $this->getSign($this->parameters);\/\/簽名\r\n        return  $this->arrayToXml($this->parameters);\r\n    }\r\n    \r\n    \/**\r\n     *     作用:post請(qǐng)求xml\r\n     *\/\r\n    function postXml()\r\n    {\r\n        $xml = $this->createXml();\r\n        $this->response = $this->postXmlCurl($xml,$this->url,$this->curl_timeout);\r\n        return $this->response;\r\n    }\r\n    \r\n    \/**\r\n     *     作用:使用證書post請(qǐng)求xml\r\n     *\/\r\n    function postXmlSSL()\r\n    {    \r\n        $xml = $this->createXml();\r\n        $this->response = $this->postXmlSSLCurl($xml,$this->url,$this->curl_timeout);\r\n        return $this->response;\r\n    }\r\n\r\n    \/**\r\n     *     作用:獲取結(jié)果,默認(rèn)不使用證書\r\n     *\/\r\n    function getResult() \r\n    {        \r\n        $this->postXml();\r\n        $this->result = $this->xmlToArray($this->response);\r\n        return $this->result;\r\n    }\r\n}<\/pre>

        三、發(fā)起支付<\/h2>

        在程序中,獲得用戶的授權(quán)碼,并填入到$authcode參數(shù)中。授權(quán)碼就是條碼上的那一串18位純數(shù)字,以10、11、12、13、14、15開頭<\/p>

        其他參數(shù)則自動(dòng)生成或者手動(dòng)輸入指定。<\/p>

        調(diào)用函數(shù)如下所示<\/p>

                \/\/全局引入微信支付類\r\n        Vendor('Wxpay.WxPayPubHelper.WxPayPubHelper');\r\n        \/\/使用統(tǒng)一支付接口\r\n        $microPay = new \\MicroPay_pub();\r\n        \/\/設(shè)置統(tǒng)一支付接口參數(shù)\r\n        $microPay->setParameter(\"body\",\"方倍商戶刷卡支付\");\/\/商品描述\r\n        $microPay->setParameter(\"out_trade_no\", \"$out_trade_no\");\/\/商戶訂單號(hào) \r\n        $microPay->setParameter(\"total_fee\", $total_fee);\/\/總金額  \r\n        $microPay->setParameter(\"auth_code\", $authcode);\/\/授權(quán)碼\r\n\r\n        \/\/獲取統(tǒng)一支付接口結(jié)果\r\n        $microPayResult = $microPay->getResult();\r\n\r\n        \/\/3. 異常判斷\r\n        if (!isset($microPayResult[\"result_code\"]) || ($microPayResult[\"result_code\"] == \"FAIL\")) {\r\n            $this->resRpcError(isset($microPayResult['result_code']) ? $microPayResult['err_code_des'] : $microPayResult['return_msg'], \"21000\");\r\n        }<\/pre>

        【相關(guān)推薦】<\/p>\n

        1. 微信公眾號(hào)平臺(tái)源碼下載<\/a><\/p>\n

        2.?分享微信公眾號(hào)開發(fā)刷卡支付的實(shí)例教程<\/a><\/p>\n

        3.?微信開發(fā)之微信支付<\/a><\/p>\n

        4.?詳解微信小程序支付功能開發(fā)錯(cuò)誤總結(jié)<\/a><\/p>"}

        亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

        Table of Contents
        1. Card payment API
        Interface address
        Input parameters
        Return results
        二、刷卡支付類實(shí)現(xiàn)
        三、發(fā)起支付
        Home WeChat Applet WeChat Development Detailed explanation of credit card payment examples for WeChat payment development

        Detailed explanation of credit card payment examples for WeChat payment development

        May 12, 2018 am 10:32 AM

        This article introduces the development process of card payment under WeChat payment. WeChat card payment refers to the payment process in which the user opens the card swiping interface of WeChat wallet, and the merchant scans the QR code and submits the payment to complete the payment.

        微信支付開發(fā)(7) 刷卡支付0微信支付開發(fā)(7) 刷卡支付1

        1. Card payment API

        Interface address

        api.mch.weixin.qq.com/pay/micropay

        Is a certificate required?

        No.

        Input parameters

        Name variable name required type example value description







        public account IDappid is String(32)wx8888888888888888 The public account ID assigned by WeChat (corpid is the This appId)
        merchant numbermch_id is String(32)1900000109Merchant number assigned by WeChat payment
        Device numberdevice_infoNoString(32)013467007045764Terminal device number (customized by the merchant, such as store number)
        Random stringnonce_strisString(32)5K8264ILTKCH16CQ2502SI8ZNMTM67VSRandom string, no longer than 32 bits. The recommended random number generation algorithm
        signaturesign isString(32)C380BEC2BFD727A4B6845133519F3AD6Signature, see signature generation algorithm for details
        Product descriptionbody isString(128) image image store-Shenzhen Tengda-QQ dollA brief description of the product, this field must be passed strictly in accordance with the specifications, for details, please see the parameter regulations
        Product detailsdetailNoString(6000)
        {
        "goods_detail":[
        {
        "goods_id":"iphone6s_16G",
        "wxpay_goods_id":"1001",
        "goods_name":"iPhone6s 16G",
        "goods_num":1,
        "price":528800,
        "goods_category":"123456",
        "body":"蘋果手機(jī)"
        },
        {
        "goods_id":"iphone6s_32G",
        "wxpay_goods_id":"1002",
        "goods_name":"iPhone6s 32G",
        "quantity":1,
        "price":608800,
        "goods_category":"123789",
        "body":"蘋果手機(jī)"
        }
        ]
        }

        Product detailed list, using Json format , please be sure to use the CDATA tag to protect the JSON text string before transmitting the signature.

        goods_detail []:
        └ goods_id String Required 32 Product number
        └ wxpay_goods_id String Optional 32 Unified product number defined by WeChat payment
        └ goods_name String Required 256 Product name
        └ goods_num Int Required product quantity
        └ price Int Required product unit price, unit is cent
        └ goods_category String Optional 32 Product category ID
        └ body String Optional 1000 Product description information

        Additional dataattachNoString(127)DescriptionAdditional data, returned as is in the query API and payment notification, this field is mainly used for merchants to carry custom data for orders
        Merchant order numberout_trade_no is String(32)1217752501201407033233368018 The order number within the merchant system, within 32 characters, can contain letters. For other instructions, see the merchant order No.
        Product detailsdetailNoString(8192)is consistent with the submitted data

        The actual submitted return

        order amounttotal_feeisInt 888Total order amount, unit is cents, can only be an integer, see payment amount
        Currency type fee_typeNoString(16)CNY is a three-letter code that conforms to the ISO4217 standard. The default is RMB: CNY. For a list of other values, see Currency Type
        Terminal IPspbill_create_ip isString(16)8.8.8.8Machine IP calling WeChat payment API
        Goods taggoods_tagNoString(32) Product tags, parameters of voucher or instant discount function, please refer to voucher or instant discount discount for details
        Specified payment methodlimit_payNoString(32)no_creditno_credit--Specify that credit card payment cannot be used
        Authorization codeauth_code isString(128)120061098828009406Scan the QR code to pay the authorization code , the device reads the barcode or QR code information in the user's WeChat

        Examples are as follows:

        <xml>
           <appid>wx2421b1c4370ec43b</appid>
           <attach>訂單額外描述</attach>
           <auth_code>120269300684844649</auth_code>
           <body>刷卡支付測(cè)試</body>
           <device_info>1000</device_info>
           <goods_tag></goods_tag>
           <mch_id>10000100</mch_id>
           <nonce_str>8aaee146b1dee7cec9100add9b96cbe2</nonce_str>
           <out_trade_no>1415757673</out_trade_no>
           <spbill_create_ip>14.17.22.52</spbill_create_ip>
           <time_expire></time_expire>
           <total_fee>1</total_fee>
           <sign>C29DB7DB1FD4136B84AE35604756362C</sign>
        </xml>

        Note: Parameter values ??can be escaped with XML, The CDATA tag is used to indicate that the data is not parsed by the XML parser.

        Return results

        Name variable name required type example value description

        #Return Status Codereturn_code isString(16)SUCCESSSUCCESS/FAIL Return informationreturn_msgNoString(128) Signature failedReturn information, if not empty, is the error reason

        當(dāng)return_code為SUCCESS的時(shí)候,還會(huì)包括以下字段:

        名稱 變量名 必填 類型 示例值 描述







        This field is the communication identification. Non-transaction identifier. You need to check the result_code to determine whether the transaction is successful.
        Signature failed
        Parameter format verification error






        公眾賬號(hào)IDappidString(32)wx8888888888888888調(diào)用接口提交的公眾賬號(hào)ID
        商戶號(hào)mch_idString(32)1900000109調(diào)用接口提交的商戶號(hào)
        設(shè)備號(hào)device_infoString(32)013467007045764調(diào)用接口提交的終端設(shè)備號(hào),
        隨機(jī)字符串nonce_strString(32)5K8264ILTKCH16CQ2502SI8ZNMTM67VS微信返回的隨機(jī)字符串
        簽名signString(32)C380BEC2BFD727A4B6845133519F3AD6微信返回的簽名,詳見簽名生成算法
        業(yè)務(wù)結(jié)果result_codeString(16)SUCCESSSUCCESS/FAIL
        錯(cuò)誤代碼err_codeString(32)SYSTEMERROR詳細(xì)參見錯(cuò)誤列表
        錯(cuò)誤代碼描述err_code_desString(128)系統(tǒng)錯(cuò)誤錯(cuò)誤返回的信息描述

        當(dāng)return_code 和result_code都為SUCCESS的時(shí),還會(huì)包括以下字段:

        名稱 變量名 必填 類型 示例值 描述







        用戶標(biāo)識(shí)openidString(128)Y用戶在商戶appid 下的唯一標(biāo)識(shí)
        是否關(guān)注公眾賬號(hào)is_subscribeString(1)Y用戶是否關(guān)注公眾賬號(hào),僅在公眾賬號(hào)類型支付有效,取值范圍:Y或N;Y-關(guān)注;N-未關(guān)注
        交易類型trade_typeString(16)MICROPAY支付類型為MICROPAY(即掃碼支付)
        付款銀行bank_typeString(16)CMC銀行類型,采用字符串類型的銀行標(biāo)識(shí),值列表詳見銀行類型
        貨幣類型fee_typeString(16)CNY符合ISO 4217標(biāo)準(zhǔn)的三位字母代碼,默認(rèn)人民幣:CNY,其他值列表詳見貨幣類型
        訂單金額total_feeInt888訂單總金額,單位為分,只能為整數(shù),詳見支付金額
        現(xiàn)金支付貨幣類型cash_fee_typeString(16)CNY符合ISO 4217標(biāo)準(zhǔn)的三位字母代碼,默認(rèn)人民幣:CNY,其他值列表詳見貨幣類型
        現(xiàn)金支付金額cash_feeInt100訂單現(xiàn)金支付金額,詳見支付金額
        微信支付訂單號(hào)transaction_idString(32)1217752501201407033233368018微信支付訂單號(hào)
        商戶訂單號(hào)out_trade_noString(32)1217752501201407033233368018商戶系統(tǒng)的訂單號(hào),與請(qǐng)求一致。
        商家數(shù)據(jù)包attachString(128)123456商家數(shù)據(jù)包,原樣返回
        支付完成時(shí)間time_endString(14)20141030133525訂單生成時(shí)間,格式為yyyyMMddHHmmss,如2009年12月25日9點(diǎn)10分10秒表示為20091225091010。詳見時(shí)間規(guī)則

        舉例如下:

        <xml>
           <return_code><![CDATA[SUCCESS]]></return_code>
           <return_msg><![CDATA[OK]]></return_msg>
           <appid><![CDATA[wx2421b1c4370ec43b]]></appid>
           <mch_id><![CDATA[10000100]]></mch_id>
           <device_info><![CDATA[1000]]></device_info>
           <nonce_str><![CDATA[GOp3TRyMXzbMlkun]]></nonce_str>
           <sign><![CDATA[D6C76CB785F07992CDE05494BB7DF7FD]]></sign>
           <result_code><![CDATA[SUCCESS]]></result_code>
           <openid><![CDATA[oUpF8uN95-Ptaags6E_roPHg7AG0]]></openid>
           <is_subscribe><![CDATA[Y]]></is_subscribe>
           <trade_type><![CDATA[MICROPAY]]></trade_type>
           <bank_type><![CDATA[CCB_DEBIT]]></bank_type>
           <total_fee>1</total_fee>
           <coupon_fee>0</coupon_fee>
           <fee_type><![CDATA[CNY]]></fee_type>
           <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>
           <out_trade_no><![CDATA[1415757673]]></out_trade_no>
           <attach><![CDATA[訂單額外描述]]></attach>
           <time_end><![CDATA[20141111170043]]></time_end>
        </xml>

        二、刷卡支付類實(shí)現(xiàn)

        在微信支付原來(lái)的微信支付類文件中,仿照統(tǒng)一支付類的方式,添加刷卡支付類如下:

        /**
         * 刷卡支付接口類
         */
        class MicroPay_pub extends Wxpay_client_pub
        {    
            function __construct() 
            {
                //設(shè)置接口鏈接
                $this->url = "https://api.mch.weixin.qq.com/pay/micropay";
                //設(shè)置curl超時(shí)時(shí)間
                $this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
            }
            
            /**
             * 生成接口參數(shù)xml
             */
            function createXml()
            {
                try
                {
                    //檢測(cè)必填參數(shù)
                    if($this->parameters["out_trade_no"] == null){
                        throw new SDKRuntimeException("缺少統(tǒng)一支付接口必填參數(shù)out_trade_no!"."<br>");
                    }elseif($this->parameters["body"] == null){
                        throw new SDKRuntimeException("缺少統(tǒng)一支付接口必填參數(shù)body!"."<br>");
                    }elseif ($this->parameters["total_fee"] == null ) {
                        throw new SDKRuntimeException("缺少統(tǒng)一支付接口必填參數(shù)total_fee!"."<br>");
                    }elseif ($this->parameters["auth_code"] == null) {
                        throw new SDKRuntimeException("缺少統(tǒng)一支付接口必填參數(shù)auth_code!"."<br>");
                    }
                       $this->parameters["appid"] = WxPayConf_pub::APPID;//公眾賬號(hào)ID
                       $this->parameters["mch_id"] = WxPayConf_pub::MCHID;//商戶號(hào)
                       $this->parameters["spbill_create_ip"] = $_SERVER[&#39;REMOTE_ADDR&#39;];//終端ip        
                    $this->parameters["nonce_str"] = $this->createNoncestr();//隨機(jī)字符串
                    $this->parameters["sign"] = $this->getSign($this->parameters);//簽名
                    // var_dump($this->parameters);
                    return  $this->arrayToXml($this->parameters);
                }catch (SDKRuntimeException $e)
                {
                    die($e->errorMessage());
                }
            }
        }

        原有的基礎(chǔ)類和請(qǐng)求類也列出如下:

        /**
         * 所有接口的基類
         */
        class Common_util_pub
        {
            function __construct() {
            }
        
            function trimString($value)
            {
                $ret = null;
                if (null != $value) 
                {
                    $ret = $value;
                    if (strlen($ret) == 0) 
                    {
                        $ret = null;
                    }
                }
                return $ret;
            }
            
            /**
             *     作用:產(chǎn)生隨機(jī)字符串,不長(zhǎng)于32位
             */
            public function createNoncestr( $length = 32 ) 
            {
                $chars = "abcdefghijklmnopqrstuvwxyz0123456789";  
                $str ="";
                for ( $i = 0; $i < $length; $i++ )  {  
                    $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);  
                }  
                return $str;
            }
            
            /**
             *     作用:格式化參數(shù),簽名過(guò)程需要使用
             */
            function formatBizQueryParaMap($paraMap, $urlencode)
            {
                $buff = "";
                ksort($paraMap);
                foreach ($paraMap as $k => $v)
                {
                    if($urlencode)
                    {
                       $v = urlencode($v);
                    }
                    //$buff .= strtolower($k) . "=" . $v . "&";
                    $buff .= $k . "=" . $v . "&";
                }
                $reqPar;
                if (strlen($buff) > 0) 
                {
                    $reqPar = substr($buff, 0, strlen($buff)-1);
                }
                return $reqPar;
            }
            
            /**
             *     作用:生成簽名
             */
            public function getSign($Obj)
            {
                foreach ($Obj as $k => $v)
                {
                    $Parameters[$k] = $v;
                }
                //簽名步驟一:按字典序排序參數(shù)
                ksort($Parameters);
                $String = $this->formatBizQueryParaMap($Parameters, false);
                //echo &#39;【string1】&#39;.$String.&#39;</br>&#39;;
                //簽名步驟二:在string后加入KEY
                $String = $String."&key=".WxPayConf_pub::KEY;
                //echo "【string2】".$String."</br>";
                //簽名步驟三:MD5加密
                $String = md5($String);
                //echo "【string3】 ".$String."</br>";
                //簽名步驟四:所有字符轉(zhuǎn)為大寫
                $result_ = strtoupper($String);
                //echo "【result】 ".$result_."</br>";
                return $result_;
            }
            
            /**
             *     作用:array轉(zhuǎn)xml
             */
            function arrayToXml($arr)
            {
                $xml = "<xml>";
                foreach ($arr as $key=>$val)
                {
                     if (is_numeric($val))
                     {
                         $xml.="<".$key.">".$val."</".$key.">"; 
        
                     }
                     else
                         $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";  
                }
                $xml.="</xml>";
                return $xml; 
            }
            
            /**
             *     作用:將xml轉(zhuǎn)為array
             */
            public function xmlToArray($xml)
            {        
                //將XML轉(zhuǎn)為array        
                $array_data = json_decode(json_encode(simplexml_load_string($xml, &#39;SimpleXMLElement&#39;, LIBXML_NOCDATA)), true);        
                return $array_data;
            }
        
            /**
             *     作用:以post方式提交xml到對(duì)應(yīng)的接口url
             */
            public function postXmlCurl($xml,$url,$second=30)
            {        
                //初始化curl        
                   $ch = curl_init();
                //設(shè)置超時(shí)
                curl_setopt($ch, CURLOP_TIMEOUT, $second);
                //這里設(shè)置代理,如果有的話
                //curl_setopt($ch,CURLOPT_PROXY, &#39;8.8.8.8&#39;);
                //curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
                curl_setopt($ch,CURLOPT_URL, $url);
                curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
                curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
                //設(shè)置header
                curl_setopt($ch, CURLOPT_HEADER, FALSE);
                //要求結(jié)果為字符串且輸出到屏幕上
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                //post提交方式
                curl_setopt($ch, CURLOPT_POST, TRUE);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
                //運(yùn)行curl
                $data = curl_exec($ch);
                curl_close($ch);
                //返回結(jié)果
                if($data)
                {
                    curl_close($ch);
                    return $data;
                }
                else 
                { 
                    $error = curl_errno($ch);
                    echo "curl出錯(cuò),錯(cuò)誤碼:$error"."<br>"; 
                    echo "<a href=&#39;http://curl.haxx.se/libcurl/c/libcurl-errors.html&#39;>錯(cuò)誤原因查詢</a></br>";
                    curl_close($ch);
                    return false;
                }
            }
        
            /**
             *     作用:使用證書,以post方式提交xml到對(duì)應(yīng)的接口url
             */
            function postXmlSSLCurl($xml,$url,$second=30)
            {
                $ch = curl_init();
                //超時(shí)時(shí)間
                curl_setopt($ch,CURLOPT_TIMEOUT,$second);
                //這里設(shè)置代理,如果有的話
                //curl_setopt($ch,CURLOPT_PROXY, &#39;8.8.8.8&#39;);
                //curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
                curl_setopt($ch,CURLOPT_URL, $url);
                curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
                curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
                //設(shè)置header
                curl_setopt($ch,CURLOPT_HEADER,FALSE);
                //要求結(jié)果為字符串且輸出到屏幕上
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
                //設(shè)置證書
                //使用證書:cert 與 key 分別屬于兩個(gè).pem文件
                //默認(rèn)格式為PEM,可以注釋
                curl_setopt($ch,CURLOPT_SSLCERTTYPE,&#39;PEM&#39;);
                curl_setopt($ch,CURLOPT_SSLCERT, dirname(__FILE__).WxPayConf_pub::SSLCERT_PATH);
                //默認(rèn)格式為PEM,可以注釋
                curl_setopt($ch,CURLOPT_SSLKEYTYPE,&#39;PEM&#39;);
                curl_setopt($ch,CURLOPT_SSLKEY, dirname(__FILE__).WxPayConf_pub::SSLKEY_PATH);
                //post提交方式
                curl_setopt($ch,CURLOPT_POST, true);
                curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
                $data = curl_exec($ch);
                //返回結(jié)果
                if($data){
                    curl_close($ch);
                    return $data;
                }
                else { 
                    $error = curl_errno($ch);
                    echo "curl出錯(cuò),錯(cuò)誤碼:$error"."<br>"; 
                    echo "<a href=&#39;http://curl.haxx.se/libcurl/c/libcurl-errors.html&#39;>錯(cuò)誤原因查詢</a></br>";
                    curl_close($ch);
                    return false;
                }
            }
            
            /**
             *     作用:打印數(shù)組
             */
            function printErr($wording=&#39;&#39;,$err=&#39;&#39;)
            {
                print_r(&#39;<pre class="brush:php;toolbar:false">&#39;);
                echo $wording."</br>";
                var_dump($err);
                print_r(&#39;
        '); } } /** * 請(qǐng)求型接口的基類 */ class Wxpay_client_pub extends Common_util_pub { var $parameters;//請(qǐng)求參數(shù),類型為關(guān)聯(lián)數(shù)組 public $response;//微信返回的響應(yīng) public $result;//返回參數(shù),類型為關(guān)聯(lián)數(shù)組 var $url;//接口鏈接 var $curl_timeout;//curl超時(shí)時(shí)間 /** * 作用:設(shè)置請(qǐng)求參數(shù) */ function setParameter($parameter, $parameterValue) { $this->parameters[$this->trimString($parameter)] = $this->trimString($parameterValue); } /** * 作用:設(shè)置標(biāo)配的請(qǐng)求參數(shù),生成簽名,生成接口參數(shù)xml */ function createXml() { $this->parameters["appid"] = WxPayConf_pub::APPID;//公眾賬號(hào)ID $this->parameters["mch_id"] = WxPayConf_pub::MCHID;//商戶號(hào) $this->parameters["nonce_str"] = $this->createNoncestr();//隨機(jī)字符串 $this->parameters["sign"] = $this->getSign($this->parameters);//簽名 return $this->arrayToXml($this->parameters); } /** * 作用:post請(qǐng)求xml */ function postXml() { $xml = $this->createXml(); $this->response = $this->postXmlCurl($xml,$this->url,$this->curl_timeout); return $this->response; } /** * 作用:使用證書post請(qǐng)求xml */ function postXmlSSL() { $xml = $this->createXml(); $this->response = $this->postXmlSSLCurl($xml,$this->url,$this->curl_timeout); return $this->response; } /** * 作用:獲取結(jié)果,默認(rèn)不使用證書 */ function getResult() { $this->postXml(); $this->result = $this->xmlToArray($this->response); return $this->result; } }

        三、發(fā)起支付

        在程序中,獲得用戶的授權(quán)碼,并填入到$authcode參數(shù)中。授權(quán)碼就是條碼上的那一串18位純數(shù)字,以10、11、12、13、14、15開頭

        其他參數(shù)則自動(dòng)生成或者手動(dòng)輸入指定。

        調(diào)用函數(shù)如下所示

                //全局引入微信支付類
                Vendor(&#39;Wxpay.WxPayPubHelper.WxPayPubHelper&#39;);
                //使用統(tǒng)一支付接口
                $microPay = new \MicroPay_pub();
                //設(shè)置統(tǒng)一支付接口參數(shù)
                $microPay->setParameter("body","方倍商戶刷卡支付");//商品描述
                $microPay->setParameter("out_trade_no", "$out_trade_no");//商戶訂單號(hào) 
                $microPay->setParameter("total_fee", $total_fee);//總金額  
                $microPay->setParameter("auth_code", $authcode);//授權(quán)碼
        
                //獲取統(tǒng)一支付接口結(jié)果
                $microPayResult = $microPay->getResult();
        
                //3. 異常判斷
                if (!isset($microPayResult["result_code"]) || ($microPayResult["result_code"] == "FAIL")) {
                    $this->resRpcError(isset($microPayResult[&#39;result_code&#39;]) ? $microPayResult[&#39;err_code_des&#39;] : $microPayResult[&#39;return_msg&#39;], "21000");
                }

        【相關(guān)推薦】

        1. 微信公眾號(hào)平臺(tái)源碼下載

        2.?分享微信公眾號(hào)開發(fā)刷卡支付的實(shí)例教程

        3.?微信開發(fā)之微信支付

        4.?詳解微信小程序支付功能開發(fā)錯(cuò)誤總結(jié)

        The above is the detailed content of Detailed explanation of credit card payment examples for WeChat payment development. For more information, please follow other related articles on the PHP Chinese website!

        Statement of this Website
        The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

        Hot AI Tools

        Undress AI Tool

        Undress AI Tool

        Undress images for free

        Undresser.AI Undress

        Undresser.AI Undress

        AI-powered app for creating realistic nude photos

        AI Clothes Remover

        AI Clothes Remover

        Online AI tool for removing clothes from photos.

        Clothoff.io

        Clothoff.io

        AI clothes remover

        Video Face Swap

        Video Face Swap

        Swap faces in any video effortlessly with our completely free AI face swap tool!

        Hot Tools

        Notepad++7.3.1

        Notepad++7.3.1

        Easy-to-use and free code editor

        SublimeText3 Chinese version

        SublimeText3 Chinese version

        Chinese version, very easy to use

        Zend Studio 13.0.1

        Zend Studio 13.0.1

        Powerful PHP integrated development environment

        Dreamweaver CS6

        Dreamweaver CS6

        Visual web development tools

        SublimeText3 Mac version

        SublimeText3 Mac version

        God-level code editing software (SublimeText3)

        Hot Topics

        PHP Tutorial
        1488
        72

      • <menuitem id="rt3hz"></menuitem>