{"id":1763,"date":"2023-03-26T22:04:56","date_gmt":"2023-03-26T14:04:56","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1763"},"modified":"2023-04-23T21:21:34","modified_gmt":"2023-04-23T13:21:34","slug":"shopify-plugin-development-experience","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/26\/shopify-plugin-development-experience\/","title":{"rendered":"Shopify\u63d2\u4ef6\u5f00\u53d1\u5165\u5751\u4f53\u9a8c"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u7531\u4e8e\u516c\u53f8\u7684\u9700\u6c42\u5f00\u53d1Shopify\u7684\u5e94\u7528\u63d2\u4ef6\u81ea\u5df1\u7279\u5730\u8bb0\u5f55\u4e0b\u3002\u7b80\u5355\u7684\u4ecb\u7ecd\u4e0bShopify\uff0c\u5b83\u662f\u7531\u6258\u6bd4\u4e9a\u65af\u00b7\u5362\u514b\u521b\u529e\u7684\u52a0\u62ff\u5927\u7535\u5b50\u5546\u52a1\u8f6f\u4ef6\u5f00\u53d1\u5546\uff0c\u603b\u90e8\u4f4d\u4e8e\u52a0\u62ff\u5927\u9996\u90fd\u6e25\u592a\u534e\uff0c\u5176\u63d0\u4f9b\u7684\u670d\u52a1\u8f6f\u4ef6Shopify\u662f\u4e00\u4e2aSaaS\u9886\u57df\u7684\u8d2d\u7269\u8f66\u7cfb\u7edf\uff0c\u9002\u5408\u8de8\u5883\u7535\u5546\u5efa\u7acb\u72ec\u7acb\u7ad9\uff0c\u7528\u6237\u652f\u4ed8\u4e00\u5b9a\u8d39\u7528\u5373\u53ef\u5728\u5176\u4e0a\u5229\u7528\u5404\u79cd\u4e3b\u9898\/\u6a21\u677f\u5efa\u7acb\u81ea\u5df1\u7684\u7f51\u4e0a\u5546\u5e97\u3002<\/p>\n<p><!-- more --><\/p>\n<p>\u5f00\u53d1\u63d2\u4ef6\u5b98\u65b9\u63a8\u8350\u662f\u7528React\u7684next.js\u670d\u52a1\u7aef\u6e32\u67d3\u6846\u67b6\u4ee5\u53canode.js\u4f5c\u4e3a\u540e\u7aef\u8bed\u8a00\u4f7f\u7528GraphQL\u5f00\u53d1\u3002\u4f5c\u4e3a\u6ca1\u63a5\u89e6\u8fc7GraphQL\u7684\u6211\u8d76\u7d27\u8865\u4e86\u4e00\u6ce2\u77e5\u8bc6\u3002\u540e\u6765\u6211\u4e00\u8def\u8dcc\u8dcc\u649e\u649e\u7ec8\u4e8e\u73b0\u5728\u662f\u4e86\u89e3\u4e86\u4e00\u4e2a\u5927\u6982\u3002\u6700\u7ec8\u6211\u8fd8\u662f\u4f7f\u7528node\u4f5c\u4e3a\u4e3b\u5165\u53e3\u7a0b\u5e8f\uff0c\u9a8c\u8bc1\u5e94\u7528\u63d2\u4ef6\u83b7\u53d6\u76f8\u5173\u7684access_token\u548c\u5546\u5e97\u5730\u5740\u3002\u5269\u4e0b\u7684\u8bf7\u6c42\u4ec0\u4e48Shopify\u63a5\u53e3\u4e5f\u6ca1\u6709\u7528GraphQL\u800c\u662f\u4f7f\u7528ResfulApi\u8ba9\u540e\u7aef\u5de5\u4f5c\u4eba\u5458\u53bb\u64cd\u4f5c\u4e86\uff0c\u7136\u540e\u6211\u8bf7\u6c42\u540e\u7aef\u63a5\u53e3\u8fdb\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\u3002<\/p>\n<h2>\u6ce8\u518c\u83b7\u53d6\u5f00\u53d1\u524d\u63d0\u8981\u7d20<\/h2>\n<p>\uff081\uff09\u521b\u5efaShopify\u5f00\u53d1\u8005\u8d26\u53f7<\/p>\n<p>\u5982\u56fe\u5728 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/developers.shopify.com\/\">https:\/\/developers.shopify.com\/<\/a> \u7f51\u7ad9\u6ce8\u518c\u76f8\u5173\u7684\u8d26\u53f7\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify\u521b\u5efa\u5f00\u53d1\u8005\u8d26\u53f7.png\" alt=\"Shopify\u521b\u5efa\u5f00\u53d1\u8005\u8d26\u53f7\" \/><\/p>\n<p>\uff082\uff09\u5728\u76f8\u5173partners\u7684\u9875\u9762\u521b\u5efa\u5546\u5e97(\u4ee5\u4f9b\u540e\u9762\u5f00\u53d1\u5e94\u7528\u4f7f\u7528)\u4ee5\u53ca\u5e94\u7528<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify%20Partners\u9875\u9762.png\" alt=\"Shopify Partners\u9875\u9762\" \/><\/p>\n<p>\uff083\uff09\u5728\u521b\u5efa\u5e94\u7528\u7684\u6709\u81ea\u5b9a\u4e49\u5e94\u7528\u548c\u516c\u5171\u5e94\u7528\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify\u521b\u5efa\u5e94\u7528.png\" alt=\"Shopify\u521b\u5efa\u5e94\u7528\" \/><\/p>\n<p>\u4e00\u822c\u6211\u4eec\u90fd\u662f\u521b\u5efa\u7684\u516c\u5171\u5e94\u7528\uff0c\u5728\u521b\u5efa\u5e94\u7528\u7684\u65f6\u5019URL\u548c\u76f8\u5173\u7684\u91cd\u5b9a\u5411URL\u90fd\u662f\u5fc5\u987b\u5199\u7684\u56e0\u4e3a\u6211\u4e5f\u6ca1\u6709\u6ce8\u518c\u57df\u540d\u5565\u7684\u5427\uff0c\u6240\u4ee5\u6b64\u65f6\u662f\u7528\u4e86ngrok\u5185\u7f51\u7a7f\u900f\uff0c\u5728\u5b98\u65b9\u7684\u5f00\u53d1\u4ecb\u7ecd\u4e2d\u4e5f\u662f\u4f7f\u7528\u8fd9\u4e2a\u3002\u5728\u6b64\u6211\u4eec\u586b\u5199\u7684URL\u5c31\u8981\u548c\u4f7f\u7528ngrok\u66b4\u9732\u51fa\u53bb\u7684\u5730\u5740\u5bf9\u5e94\u4e86\uff0c\u4e0d\u8fc7\u4f7f\u7528node\u7684koa\u6846\u67b6\u6709\u4e2a\u4e13\u95e8\u7684\u4e2d\u95f4\u4ef6\u4e5f\u662f\u5b98\u65b9\u4f7f\u7528\u7684\u91cd\u5b9a\u5411\u5730\u5740\u90fd\u662f\u57df\u540d\u540e\u52a0\u4e0a\u4e86shopify\/auth \u4f8b\u5982\uff1aURL:<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/30aca829.ngrok.io\">https:\/\/30aca829.ngrok.io<\/a>, \u91cd\u5b9a\u5411URL:<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/30aca829.ngrok.io\/shopify\/auth\/\">https:\/\/30aca829.ngrok.io\/shopify\/auth\/<\/a> \uff08\u7535\u8111\u91cd\u542f\u91cd\u65b0\u66b4\u9732\u51fa\u53bb\u8fd9\u4e2a\u8fde\u4e2a\u5730\u5740\u90fd\u662f\u8981\u91cd\u65b0\u586b\u4e00\u904d\uff0c\u7136\u540ekoa\u7684\u4e2d\u95f4\u4ef6\u5c31\u4f1a\u8df3\u8f6c\u5230 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/30aca829.ngrok.io\/shopify\/auth\/\">https:\/\/30aca829.ngrok.io\/shopify\/auth\/<\/a> \u8fdb\u884c\u76f8\u5173\u7684\u9a8c\u8bc1\u64cd\u4f5c\u3002\u7136\u540e\u5728\u540e\u671f\u6211\u4eec\u6ca1\u6709\u7528koa\u4f5c\u4e3a\u5165\u53e3\u8fd9\u4e2a\u5730\u5740\u4e5f\u662f\u53ef\u4ee5\u81ea\u5df1\u60f3\u600e\u4e48\u586b\u5c31\u600e\u4e48\u586b\uff09\u3002<\/p>\n<p>\uff084\uff09\u521b\u5efa\u5b8c\u6210\uff08\u62ff\u53d6\u76f8\u5173\u7684\u5bc6\u94a5\u5f88\u91cd\u8981\uff01\uff01\u5f88\u91cd\u8981\uff01\uff01\u4f5c\u4e3a\u5f00\u53d1\u8bfb\u53d6\u6570\u636e\u548c\u8bf7\u6c42\u5b98\u65b9api\u4f7f\u7528\uff09<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify\u5e94\u7528API\u79d8\u94a5.png\" alt=\"Shopify\u5e94\u7528API\u79d8\u94a5\" \/><\/p>\n<h2>\u7f16\u5199\u5f00\u53d1\u73af\u5883\u7a0b\u5e8f<\/h2>\n<p>\uff081\uff09\u521b\u5efa\u9879\u76ee\u76ee\u5f55\uff08sample-app\uff09\uff0c\u5e76\u4f7f\u7528npm\u521d\u59cb\u5316\u9879\u76ee\u76ee\u5f55<\/p>\n<pre><code class=\"language-bash\">npm init -y<\/code><\/pre>\n<p>\uff082\uff09\u5b89\u88c5\u76f8\u5173\u4f9d\u8d56<\/p>\n<pre><code class=\"language-bash\">npm install --save react react-dom next<\/code><\/pre>\n<p>\uff083\uff09\u56e0\u4e3a\u662f\u7528next.js\u6240\u4ee5\u4e0d\u719f\u6089\u7684\u8fd8\u5f97\u770b\u770b\u5b98\u65b9\u6587\u6863 nextjs.frontendx.cn\/<\/p>\n<p>\u521b\u5efa\u6587\u4ef6pages\u5e76\u5728\u4e0b\u9762\u65b0\u5efa<code>index.js<\/code><\/p>\n<pre><code class=\"language-javascript\">const Index = () =&gt; (\n  &lt;div&gt;\n    &lt;p&gt;Sample app using React and Next.js&lt;\/p&gt;\n  &lt;\/div&gt;\n);\n\nexport default Index;<\/code><\/pre>\n<p>\u6dfb\u52a0\u76f8\u5173\u8fd0\u884c\u547d\u4ee4\u6253\u5f00<code>package.json<\/code>\u6587\u4ef6\u6dfb\u52a0<\/p>\n<pre><code class=\"language-json\">{\n  &quot;scripts&quot;: {\n    &quot;test&quot;: &quot;echo \\&quot;Error: no test specified\\&quot; &amp;&amp; exit 1&quot;,\n    &quot;dev&quot;: &quot;next&quot;,\n    &quot;build&quot;: &quot;next build&quot;,\n    &quot;start&quot;: &quot;next start&quot;\n  }\n}<\/code><\/pre>\n<p>\uff084\uff09\u8fd0\u884c\u5f00\u53d1\u73af\u5883<\/p>\n<pre><code class=\"language-bash\">npm run dev<\/code><\/pre>\n<p>\u5230\u8fd9\u91cc\u5e94\u8be5\u662f\u521b\u5efa\u4e00\u4e2a<code>next.js<\/code>\u9879\u76ee\u7136\u540e\u63a5\u4e0b\u6765\u5bf9\u63a5\u5230Shopify<\/p>\n<p>\uff085\uff09\u4f7f\u7528ngrok\u66b4\u9732\u51fa\u53bb\u81ea\u5df1\u76843000\u7aef\u53e3\u56e0\u4e3a<code>next.js<\/code>\u542f\u52a8\u7684\u9ed8\u8ba4\u662f3000\u7aef\u53e3<\/p>\n<pre><code class=\"language-bash\">ngrok http 3000<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify%20koa\u6388\u6743\u4f7f\u7528ngrok\u66b4\u9732\u7aef\u53e3.png\" alt=\"Shopify koa\u6388\u6743\u4f7f\u7528ngrok\u66b4\u9732\u7aef\u53e3\" \/><\/p>\n<p>\u7136\u540e\u5728\u81ea\u5df1\u521b\u5efa\u7684\u5e94\u7528\u4e2d\u8bbe\u7f6e\u4e2d\u6dfb\u52a0\u5bf9\u5e94\u7684url\uff08\u5f97\u7528https\u7684\uff09\u5c31\u5728\u4e0a\u9762\u6240\u8bf4\u7684\u586b\u5199url<\/p>\n<p>\uff086\uff09\u4f7f\u7528node\u7684 koa\u6765\u8fdb\u884c\u6e32\u67d3\u9875\u9762\u64cd\u4f5c<\/p>\n<ul>\n<li>\u521b\u5efaenv\u73af\u5883\u53d8\u91cf\u6587\u4ef6\u5e76\u5199\u5165\u5728\u4e0a\u9762\u521b\u5efa\u7684\u5e94\u7528\u7684KEY<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">SHOPIFY_API_KEY=&#039;YOUR API KEY FROM SHOPIFY PARTNERS DASHBOARD&#039;\nSHOPIFY_API_SECRET_KEY=&#039;YOUR API SECRET KEY FROM SHOPIFY PARTNERS DASHBOARD&#039;<\/code><\/pre>\n<ul>\n<li>\u5b89\u88c5\u76f8\u5173Shopify\u7684\u9a8c\u8bc1koa\u4e2d\u95f4\u4ef6<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">npm install --save koa @shopify\/koa-shopify-auth @shopify\/koa-shopify-graphql-proxy dotenv koa-session isomorphic-fetch<\/code><\/pre>\n<ul>\n<li>\u521b\u5efa<code>server.js<\/code>\u5199\u5165\u76f8\u5173\u9a8c\u8bc1\u4ee3\u7801<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">require(&#039;isomorphic-fetch&#039;);\nconst dotenv = require(&#039;dotenv&#039;);\nconst Koa = require(&#039;koa&#039;);\nconst next = require(&#039;next&#039;);\nconst { default: createShopifyAuth } = require(&#039;@shopify\/koa-shopify-auth&#039;);\nconst { verifyRequest } = require(&#039;@shopify\/koa-shopify-auth&#039;);\nconst session = require(&#039;koa-session&#039;);\n\ndotenv.config();\n\/\/ graphql\u7684\u76f8\u5173\u4e2d\u95f4\u4ef6\nconst { default: graphQLProxy } = require(&#039;@shopify\/koa-shopify-graphql-proxy&#039;); \nconst { ApiVersion } = require(&#039;@shopify\/koa-shopify-graphql-proxy&#039;);\n\nconst port = parseInt(process.env.PORT, 10) || 3000;\nconst dev = process.env.NODE_ENV !== &#039;production&#039;;\nconst app = next({ dev });\nconst handle = app.getRequestHandler();\n\nconst { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env; \/\/ \u73af\u5883\u53d8\u91cf\u91cc\u8bfb\u53d6 api-key\u4e0eapi-secret-key\napp.prepare().then(() =&gt; {\n  const server = new Koa();\n  server.use(session(server));\n  server.keys = [SHOPIFY_API_SECRET_KEY];\n\n  server.use(\n    createShopifyAuth({\n      apiKey: SHOPIFY_API_KEY,\n      secret: SHOPIFY_API_SECRET_KEY, \n      scopes: [&#039;read_products&#039;, &#039;write_products&#039;], \/\/\u586b\u5199\u76f8\u5173\u5e94\u7528api\u76f8\u5173\u8bf7\u6c42\u7684\u6743\u9650\n      afterAuth(ctx) {\n        const { shop, accessToken } = ctx.session; \/\/ \u901a\u8fc7session\u62ff\u53d6\u76f8\u5173\u5546\u5e97\u5730\u5740\u4ee5\u53ca\u8bf7\u6c42api\u9700\u8981\u7684accessToken\n        ctx.cookies.set(&#039;shopOrigin&#039;, shop, { httpOnly: false }); \n        ctx.redirect(&#039;\/&#039;); \/\/ \u91cd\u5b9a\u5411\u5230index\u9996\u9875\n      },\n    }),\n  );\n\n  server.use(verifyRequest());\n  server.use(async (ctx) =&gt; {\n    await handle(ctx.req, ctx.res);\n    ctx.respond = false;\n    ctx.res.statusCode = 200;\n    return\n  });\n  server.use(graphQLProxy({version: ApiVersion.October19})) \/\/ \u8fd9\u91cc\u586b\u5199\u76f8\u5173api\u7684\u7248\u672c\n\n  server.listen(port, () =&gt; {\n    console.log(`&gt; Ready on http:\/\/localhost:${port}`); \/\/ \u76d1\u542c\u7aef\u53e3\n  });\n});<\/code><\/pre>\n<ul>\n<li>\u4fee\u6539<code>package.json<\/code>\u6587\u4ef6\u4f7f\u7528\u6211\u4eec\u7684<code>server.js<\/code>\u6765\u542f\u52a8\u9879\u76ee<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;scripts&quot;: {\n    &quot;test&quot;: &quot;echo \\&quot;Error: no test specified\\&quot; &amp;&amp; exit 1&quot;,\n    &quot;dev&quot;: &quot;node server.js&quot;,\n    &quot;start&quot;: &quot;NODE_ENV=production node server.js&quot;,\n    &quot;build&quot;: &quot;next build&quot;,\n  }\n}<\/code><\/pre>\n<ul>\n<li>\u73b0\u5728\u6211\u4eec\u542f\u52a8\u9879\u76ee\u5e76\u4e14\u7528ngrok\u66b4\u9732\u51fa\u53bb\u7684\u57df\u540d\u5c31\u80fd\u770b\u5230<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify%20koa\u6388\u6743\u8df3\u8f6c.png\" alt=\"Shopify koa\u6388\u6743\u8df3\u8f6c\" \/><\/p>\n<p>\u8fd9\u91cc\u8fd8\u8981\u5728\u57df\u540d\u7684shop\u586b\u5199\u6211\u4eec\u7684\u5546\u5e97\u5730\u5740\u4f8b\u5982\u6211\u81ea\u5df1\u7684\uff1a<\/p>\n<pre><code>https:\/\/e44132cd.ngrok.io\/auth\/inline?shop=jetbn.myshopify.com<\/code><\/pre>\n<p>\u4e00\u5207\u586b\u5199\u5c31\u7eea\u4e4b\u540e\u4e00enter\u9875\u9762\u5c31\u81ea\u52a8\u8df3\u8f6c\u4e86\u3002<\/p>\n<p>\u6700\u540e\u5c55\u793a\u7684\u9875\u9762\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6280\u672f\/Shopify\u6388\u6743\u5b8c\u6210\u8df3\u8f6c\u9875\u9762.png\" alt=\"Shopify\u6388\u6743\u5b8c\u6210\u8df3\u8f6c\u9875\u9762\" \/><\/p>\n<h2>\u6298\u817e\u5176\u4ed6\u6846\u67b6\u5c1d\u8bd5<\/h2>\n<p>\u524d\u524d\u540e\u540e\u90fd\u662f\u4f7f\u7528React\u7684next.js\u5f00\u53d1\u4e86\u4e24\u4e09\u4e2a\u5e94\u7528\uff0c\u611f\u89c9\u5c31\u662f\u5f00\u53d1\u7684\u65f6\u5019\u592a\u9ebb\u70e6\u4e86\uff0c\u603b\u8981\u5185\u7f51\u7a7f\u900f\uff0c\u800c\u4e14\u5c55\u793a\u7684\u9875\u9762\u90fd\u662fShopify\u7684\u7684\u81ea\u5df1\u5e73\u53f0\u4e0a\uff0c\u800c\u4e14\u5f00\u53d1\u5199\u5b8c\u4ee3\u7801\u7b49\u5b83\u54cd\u5e94\u8fc7\u6765\u8fd8\u5f88\u6162\u3002\u5c31\u8fd9\u539f\u56e0\u6211\u53c8\u5f00\u59cb\u6298\u817e\u4e86\u5bfb\u6c42\u5176\u4ed6\u7684\u65b9\u6848\u770b\u770b\u6709\u6ca1\u6709\u80fd\u5728\u81ea\u5df1\u5f00\u53d1\u5b8c\u4e86\u518d\u5230\u5b83\u90a3\u4e0a\u9762\uff0c\u800c\u4e14\u8ba9\u9a8c\u8bc1Shopify\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u8ba9\u6211\u4eec\u7684\u540e\u7aef\u5c0f\u54e5\u6765\u64cd\u4f5c\u3002\u6700\u7ec8\u6211\u524d\u7aef\u9009\u62e9Vue\u5e76\u4e14\u9a8c\u8bc1\u90fd\u653e\u540e\u7aef\u4e86\uff0c\u8fd9\u6837\u6211\u5c31\u80fd\u50cf\u5e73\u5e38\u5f00\u53d1Vue\u9879\u4e00\u6837\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u4ecb\u7ecd\u4e0b\u6211\u7eaf\u524d\u7aef\u8fdb\u884cShopify\u7684\u9a8c\u8bc1\u64cd\u4f5c\u4f7f\u7528vue\uff08\u524d\u63d0\u8981\u7d20\u5185\u7f51\u7a7f\u900f\uff0c\u4e0d\u8fc7\u5f00\u53d1\u7684\u65f6\u5019\u4e0d\u9700\u8981\uff09<\/p>\n<p>\uff081\uff09\u6dfb\u52a0\u5b89\u88c5\u5e94\u7528\u8def\u7531<\/p>\n<pre><code class=\"language-javascript\">  {\n    path: &#039;\/shopify\/install&#039;,\n    beforeEnter(to, _from, next) {\n      if (to.query.shop) {  \/\/\u8981\u5728\u57df\u540d\u540e\u6dfb\u52a0\u5f00\u53d1\u7684\u5546\u5e97\u5730\u5740\n          const shop = to.query.shop,\n          scopes = &#039;read_orders,read_products,write_products&#039;, \/\/ api\u6743\u9650\n          \/\/ \u91cd\u5b9a\u5411\u5730\u5740\u5c31\u662f\u5728\u521b\u5efa\u5e94\u7528\u7684\u65f6\u5019\u586b\u5199\u7684\u7b2c\u4e8c\u4e2a\uff08\u91cd\u5b9a\u5411URL\u53ef\u4ee5\u81ea\u5df1\u968f\u610f\u5199\u4e86\uff09\uff0c\u6211\u8fd9\u91cc\u662f\u57df\u540d\u52a0\/shopify\/auth\n          redirect_uri = &#039;https:\/\/&#039; + process.env.VUE_APP_ROOT_URL + &#039;\/shopify\/auth&#039;, \n          \/\/ \u62fc\u63a5\u5b89\u88c5\u5e94\u7528\u5730\u5740\u9700\u8981SHOPIFY_API_KEY\u6211\u586b\u5199\u5728\u6211\u7684.env\u6587\u4ef6\u4e2d\u4e86\n          install_url =\n                &#039;http:\/\/&#039; + shop + &#039;\/admin\/oauth\/authorize?client_id=&#039; +\n                process.env.VUE_APP_SHOPIFY_API_KEY +\n                &#039;&amp;scope=&#039; + scopes + &#039;&amp;redirect_uri=&#039; + redirect_uri\n        \/\/ \u672c\u5730\u8df3\u8f6c\u5b89\u88c5\u5730\u5740\n        window.location = install_url\n      } else {\n        next({ path: &#039;\/error&#039; })\n      }\n    }\n  },<\/code><\/pre>\n<p>\uff082\uff09\u91cd\u5b9a\u5411\u9a8c\u8bc1\u8def\u7531<\/p>\n<pre><code class=\"language-javascript\">  {\n    path: &#039;\/shopify\/auth&#039;,\n    beforeEnter(to, _from, next) {\n    \/\/ \u901a\u8fc7\u56de\u8c03\u7684url\u83b7\u53d6\u76f8\u5173\u7684\u53c2\u6570\n      const shop = to.query.shop,\n        hmac = to.query.hmac,\n        code = to.query.code\n    \/\/ \u4f7f\u7528SHOPIFY_API_SECRET_KEY\u9a8c\u8bc1 \u5e76\u4e14\u4e4b\u540e\u62ff\u53d6access_token\uff08\u8fd9\u6b65\u6ca1\u5199\uff09\n      if (shop &amp;&amp; hmac &amp;&amp; code) {\n        const map = Object.assign({}, to.query)\n        delete map[&#039;signature&#039;]\n        delete map[&#039;hmac&#039;]\n        const message = querystring.stringify(map)\n        const encrypted =\n          crypto.createHmac(&#039;sha256&#039;, process.env.VUE_APP_SHOPIFY_API_SECRET_KEY)\n                .update(message)\n                .digest(&#039;hex&#039;)\n        \/\/ const providedHmac =  Buffer.from(hmac, &#039;utf-8&#039;)\n        \/\/ const generatedHash = Buffer.from(encrypted, &#039;utf-8&#039;)\n\n        let hashEquals = false\n\n        try {\n          \/\/ later: Auth fails with `crypto.timingSafeEqual`\n          \/\/ hashEquals = crypto.timingSafeEqual(generatedHash, providedHmac)\n          hashEquals = hmac === encrypted\n        } catch (e) {\n          hashEquals = false\n        }\n\n        if (!hashEquals) {\n          next({ path: &#039;\/error&#039; })\n        } else {\n          next(&#039;\/&#039;)\n        }\n      } else {\n        next({ path: &#039;\/error&#039; })\n      }\n    }\n  }<\/code><\/pre>\n<p>Vue\u8fd9\u76f8\u5173\u7684\u9a8c\u8bc1\u65b9\u6848\u4e5f\u662f\u4eceGithub\u4e0a\u9762\u635e\u7684\uff0c\u7279\u5730\u8bb0\u5f55\u4e0b\u3002\u5177\u4f53\u5730\u5740\u5fd8\u4e86\uff0c\u6709\u9700\u8981\u81ea\u5df1\u53ef\u4ee5\u641c\u641c\u3002<\/p>\n<h2>\u53c2\u8003\u6587\u6863<\/h2>\n<ul>\n<li>Shopify Apps(\u5f00\u53d1\u5e94\u7528): <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/shopify.dev\/concepts\/apps\">https:\/\/shopify.dev\/concepts\/apps<\/a><\/li>\n<li>Shopify Developers(\u5b98\u65b9\u5f00\u53d1\u6587\u6863): <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/developers.shopify.com\/\">https:\/\/developers.shopify.com\/<\/a><\/li>\n<li>Shopify Polaris(\u5b98\u65b9UI\u6846\u67b6): <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/polaris.shopify.com\/\">https:\/\/polaris.shopify.com\/<\/a><\/li>\n<li>Webhook: <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/shopify.dev\/docs\/admin-api\/rest\/reference\/events\/webhook\">https:\/\/shopify.dev\/docs\/admin-api\/rest\/reference\/events\/webhook<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u7531\u4e8e\u516c\u53f8\u7684\u9700\u6c42\u5f00\u53d1Shopify\u7684\u5e94\u7528\u63d2\u4ef6\u81ea\u5df1\u7279\u5730\u8bb0\u5f55\u4e0b\u3002\u7b80\u5355\u7684\u4ecb\u7ecd\u4e0bShopify\uff0c\u5b83\u662f\u7531\u6258\u6bd4\u4e9a\u65af\u00b7\u5362 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[445],"tags":[],"class_list":["post-1763","post","type-post","status-publish","format-standard","hentry","category-shopify"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1763"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1763\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}