{"id":521,"date":"2022-04-11T18:34:40","date_gmt":"2022-04-11T10:34:40","guid":{"rendered":"https:\/\/sit-open-doc.jkos.app\/?docs=%e7%b7%9a%e4%b8%8a%e6%94%af%e4%bb%98onlinepay\/%e4%b8%b2%e6%8e%a5%e8%aa%aa%e6%98%8e\/%e5%8a%a0%e7%b0%bd%e5%8a%a0%e5%af%86%e8%aa%aa%e6%98%8e"},"modified":"2025-04-25T19:05:19","modified_gmt":"2025-04-25T11:05:19","slug":"%e5%8a%a0%e7%b0%bd%e5%8a%a0%e5%af%86%e8%aa%aa%e6%98%8e","status":"publish","type":"docs","link":"https:\/\/open-doc.jkos.com\/?docs=%e7%b7%9a%e4%b8%8a%e6%94%af%e4%bb%98onlinepay\/%e4%b8%b2%e6%8e%a5%e8%aa%aa%e6%98%8e\/%e5%8a%a0%e7%b0%bd%e5%8a%a0%e5%af%86%e8%aa%aa%e6%98%8e","title":{"rendered":"\u52a0\u7c3d\u52a0\u5bc6\u8aaa\u660e (Signature Generation Rule)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u898f\u5247\u8aaa\u660e (Description)<\/h2>\n\n\n\n<p>\u7c3d\u7ae0\u7522\u751f\u898f\u5247\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5c07\u5b57\u4e32\u7684 request payload \u4ee5 UTF-8 \u7de8\u78bc\uff0c\u6210\u70ba&#8221;input byte&#8221;\u3002<\/li>\n\n\n\n<li>\u5c07\u8857\u53e3\u63d0\u4f9b\u4e32\u63a5\u4f7f\u7528\u7684 Secret key \u4ee5 UTF-8 \u7de8\u78bc\uff0c\u6210\u70ba&#8221;secret key byte&#8221;\u3002<\/li>\n\n\n\n<li>\u5c07&#8221;input byte&#8221;\u52a0\u4e0a&#8221;secret key byte&#8221;\u900f\u904e HMAC-SHA256 \u96dc\u6e4a\u6f14\u7b97\u6cd5\u4e26\u8f49\u63db\u70ba16\u9032\u4f4d\u5b57\u4e32\u4f5c\u70ba &#8220;digest&#8221;\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\"\/>\n\n\n\n<p>Signature Generation Rule :<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Encode the request payload into bytes using UTF-8 as &#8220;input byte&#8221;. For example, if the request payload is {\u201ca\u201d:1, \u201cb\u201d:\u201c13\u201d}, the result is bytes whose hex representation is 7b2261223a312c202262223a223133227d<\/li>\n\n\n\n<li>Also, Encode your Secret key into bytes using UTF-8 as &#8220;secret key byte&#8221;.<\/li>\n\n\n\n<li>Using the bytes of &#8220;input byte&#8221; and &#8220;secret key byte&#8221; by HMAC-SHA256 as the hash function and transfer hexadecimal as &#8220;digest&#8221;.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b (Example) &#8211; Entry API (Method=Post)<\/h2>\n\n\n\n<p><strong>\u6b65\u9a5f\u4e00\uff1a<\/strong><\/p>\n\n\n\n<p>\u5c07\u5b57\u4e32\u7684 request payload\u4ee5 UTF-8 \u7de8\u78bc\uff0crequest body\u7bc4\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">{\"platform_order_id\":\"demo-order-001\",\"store_id\":\"35f12dff-1581-11e9-a054-00505684fd45\",\"currency\": \"TWD\",\"total_price\":10,\"final_price\":10,\"unredeem\":10,\"result_display_url\":\"https:\/\/display.com\",\"result_url\":\"https:\/\/result-callback.xxx\/xxx\"}<\/code><\/pre>\n\n\n\n<p><strong>\u6b65\u9a5f\u4e8c\uff1a<\/strong><\/p>\n\n\n\n<p>\u9808\u8207\u8857\u53e3\u652f\u4ed8\u7533\u8acb\u5e73\u53f0Secret Key\uff0c\u91d1\u9470\u7bc4\u4f8b\u70ba Secret key = <code>r0odDC1e9LHXDmxuvmOv9bgaWLf2CXB2c4gMheoFucVKNMi1K0Id9zwRHJF1r-kdtAKriKgb11VDlo7Kb8R-FQ<\/code>\uff0c\u4e26\u5c07 Secret key \u4ee5UTF-8 \u7de8\u78bc<\/p>\n\n\n\n<p><strong>\u6b65\u9a5f\u4e09\uff1a<\/strong><\/p>\n\n\n\n<p>\u5c07\u6b65\u9a5f\u4e00\u7522\u751f\u7684\u5b57\u7bc0\u900f\u904e HMAC-SHA256\u6f14\u7b97\u6cd5\uff0c\u4ee5\u6b65\u9a5f\u4e8c\u7684\u5b57\u7bc0\u4f5c\u70ba\u79d8\u5bc6\u9470\u5319\u9032\u884c\u52a0\u7c3d\uff0c\u5373\u7522\u751f hexdigest \u4f5c\u70ba digest\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">{\"platform_order_id\":\"demo-order-001\",\"store_id\":\"35f12dff-1581-11e9-a054-00505684fd45\",\"currency\": \"TWD\",\"total_price\":10,\"final_price\":10,\"unredeem\":10,\"result_display_url\":\"https:\/\/display.com\",\"result_url\":\"https:\/\/result-callback.xxx\/xxx\"}\n\/*\nSecret key='r0odDC1e9LHXDmxuvmOv9bgaWLf2CXB2c4gMheoFucVKNMi1K0Id9zwRHJF1r-kdtAKriKgb11VDlo7Kb8R-FQ'\n*\/\nDIGEST: 3577609b058ab85c2d0a00a5421a991979ed6b9f549476e9a82476dc1b70d876<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b (Example) &#8211; Inquiry API (Method=Get)<\/h2>\n\n\n\n<p><strong>\u6b65\u9a5f\u4e00\uff1a<\/strong><\/p>\n\n\n\n<p>\u5c07\u5b57\u4e32\u7684 request payload\u4ee5 UTF-8 \u7de8\u78bc\uff0crequest parameter\u7bc4\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">platform_order_ids=test123,demo-order-001<\/code><\/pre>\n\n\n\n<p><strong>\u6b65\u9a5f\u4e8c\uff1a<\/strong><\/p>\n\n\n\n<p>\u9808\u8207\u8857\u53e3\u652f\u4ed8\u7533\u8acb\u5e73\u53f0Secret Key\uff0c\u91d1\u9470\u7bc4\u4f8b\u70ba Secret key = <code>r0odDC1e9LHXDmxuvmOv9bgaWLf2CXB2c4gMheoFucVKNMi1K0Id9zwRHJF1r-kdtAKriKgb11VDlo7Kb8R-FQ<\/code>\uff0c\u4e26\u5c07 Secret key \u4ee5UTF-8 \u7de8\u78bc<\/p>\n\n\n\n<p><strong>\u6b65\u9a5f\u4e09\uff1a<\/strong><\/p>\n\n\n\n<p>\u5c07\u6b65\u9a5f\u4e00\u7522\u751f\u7684\u5b57\u7bc0\u900f\u904e HMAC-SHA256\u6f14\u7b97\u6cd5\uff0c\u4ee5\u6b65\u9a5f\u4e8c\u7684\u5b57\u7bc0\u4f5c\u70ba\u79d8\u5bc6\u9470\u5319\u9032\u884c\u52a0\u7c3d\uff0c\u5373\u7522\u751f hexdigest \u4f5c\u70ba digest\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">DIGEST: 7778b95890af17c5b41e8cef957f4769e7bfecc79e9f9ee555923293ebd8e880<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7c3d\u7ae0\u9a57\u8b49\u5de5\u5177<\/h2>\n\n\n\n<script type=\"text\/javascript\" src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/crypto-js\/3.1.2\/rollups\/hmac-sha256.js\"><\/script>\n\n<script>\n  function generateSignature() {\n    let requestType = document.getElementById(\"requestType\").value;\n    let requestData = document.getElementById(\"requestData\").value.trim();\n    let secretKey = document.getElementById(\"secretKey\").value.trim();\n    let errorDiv = document.getElementById(\"error\");\n    let output = document.getElementById(\"output\");\n    \n    errorDiv.innerHTML = \"\";\n    output.value = \"\";\n    \n    if (!secretKey) {\n      errorDiv.innerHTML = \"\u8acb\u8f38\u5165 Secret Key\";\n      return;\n    }\n    \n    if (!requestData) {\n      errorDiv.innerHTML = \"\u8acb\u8f38\u5165\u8acb\u6c42\u5167\u5bb9\";\n      return;\n    }\n    \n    try {\n      let inputData;\n      \n      if (requestType === \"GET\") {\n        \/\/ GET \u8acb\u6c42: \u76f4\u63a5\u4f7f\u7528 Query String\n        inputData = requestData;\n      } else {\n        \/\/ \u5176\u4ed6\u8acb\u6c42 (POST \/ PUT \/ PATCH): JSON \u683c\u5f0f\u5316\u8655\u7406\n        inputData = requestData;\n      }\n      \n      \/\/ \u7522\u751f HMAC-SHA256 \u7c3d\u540d\n      let signature = CryptoJS.HmacSHA256(inputData, secretKey);\n      \n      \/\/ \u8f49\u63db\u70ba 16 \u9032\u4f4d\u683c\u5f0f (\u5c0f\u5beb)\n      let digest = signature.toString(CryptoJS.enc.Hex);\n      \n      output.value = digest;\n    } catch (e) {\n      errorDiv.innerHTML = \"\u8acb\u8f38\u5165\u6b63\u78ba\u7684\u8acb\u6c42\u5167\u5bb9 (GET Query String \u6216 JSON Body)\";\n    }\n  }\n<\/script>\n\n<div class=\"w-75\">\n  <div class=\"mb-3\">\n    <div class=\"mb-1\">\u8acb\u6c42\u985e\u578b\uff1a<\/div>\n    <select id=\"requestType\" class=\"form-control\">\n      <option value=\"GET\">GET<\/option>\n      <option value=\"POST\">POST \/ PUT \/ PATCH<\/option>\n    <\/select>\n  <\/div>\n\n  <div class=\"mb-3\">\n    <div class=\"mb-1\">\u8acb\u6c42\u5167\u5bb9\uff1a(input byte)<\/div>\n    <textarea id=\"requestData\" class=\"form-control\" rows=\"5\" placeholder='GET: platform_order_ids=test123&#038;auth_no=123\nPOST: {\"platform_order_id\":\"demo-order-001\",\"store_id\":\"35f12dff-1581-11e9-a054-00505684fd45\",\"currency\":\"TWD\",\"total_price\":10,\"final_price\":10,\"unredeem\":10,\"result_display_url\":\"https:\/\/display.com\",\"result_url\":\"https:\/\/result-callback.xxx\/xxx\"}'><\/textarea>\n  <\/div>\n\n  <div class=\"mb-3\">\n    <div class=\"mb-1\">Secret Key\uff1a<\/div>\n    <input id=\"secretKey\" type=\"text\" class=\"form-control\" placeholder=\"\u8f38\u5165 Secret Key\">\n  <\/div>\n\n  <button type=\"button\" class=\"btn btn-info mb-2 p-2\" onclick=\"generateSignature()\">\n    \u8a08\u7b97\u7c3d\u540d\n  <\/button>\n\n  <div class=\"mb-3\">\n    <div id=\"error\" style=\"color: red;\"><\/div>\n  <\/div>\n\n  <div class=\"mb-3\">\n    <div class=\"mb-1\">\u7c3d\u540d\u7d50\u679c\uff1a<\/div>\n    <textarea id=\"output\" class=\"form-control\" rows=\"3\" readonly><\/textarea>\n  <\/div>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">sample code<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">PHP<\/h4>\n\n\n\n<p>\u53c3\u8003\u5de5\u5177\uff1a<a href=\"https:\/\/www.tehplayground.com\/uEl6FSUO5YaJHHVH\">https:\/\/www.tehplayground.com\/uEl6FSUO5YaJHHVH<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$sig = hash_hmac('sha256', $string, $secret)\n\nsecretkey\uff1a\nr0odDC1e9LHXDmxuvmOv9bgaWLf2CXB2c4gMheoFucVKNMi1K0Id9zwRHJF1r-kdtAKriKgb11VDlo7Kb8R-FQ\n\ninput:\nplatform_order_ids=test123,demo-order-001\n\nresult:\n7778b95890af17c5b41e8cef957f4769e7bfecc79e9f9ee555923293ebd8e880<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">JAVA<\/h4>\n\n\n\n<p>\u53c3\u8003\u5de5\u5177\uff1a<a href=\"https:\/\/reurl.cc\/M0YKXk\">https:\/\/reurl.cc\/M0YKXk<\/a><\/p>\n","protected":false},"featured_media":0,"parent":43,"menu_order":1,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-521","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=521"}],"version-history":[{"count":19,"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs\/521\/revisions"}],"predecessor-version":[{"id":1370,"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs\/521\/revisions\/1370"}],"up":[{"embeddable":true,"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs\/43"}],"next":[{"title":"\u5e38\u898b\u554f\u984c (Q&A)","link":"https:\/\/open-doc.jkos.com\/?docs=%e7%b7%9a%e4%b8%8a%e6%94%af%e4%bb%98onlinepay\/%e4%b8%b2%e6%8e%a5%e8%aa%aa%e6%98%8e\/%e5%b8%b8%e8%a6%8b%e5%95%8f%e9%a1%8c","href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs\/524"}],"prev":[{"title":"API \u5354\u8b70\u898f\u5247 (API Protocol Rules)","link":"https:\/\/open-doc.jkos.com\/?docs=%e7%b7%9a%e4%b8%8a%e6%94%af%e4%bb%98onlinepay\/%e4%b8%b2%e6%8e%a5%e8%aa%aa%e6%98%8e\/api-%e5%8d%94%e8%ad%b0%e8%a6%8f%e5%89%87","href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=\/wp\/v2\/docs\/437"}],"wp:attachment":[{"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=521"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/open-doc.jkos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}