回调通知
Last updated
2023-07-12 09:43:59
{"value":"\u56de\u8c03\u901a\u77e5\u662f\u6307\u5ba2\u6237\u7aef\u5728\u4e0a\u4f20\u65f6\u6307\u5b9a\u670d\u52a1\u7aef\u5728\u5904\u7406\u5b8c\u4e0a\u4f20\u8bf7\u6c42\u540e\uff0c\u5e94\u8be5\u901a\u77e5\u67d0\u4e2a\u7279\u5b9a\u670d\u52a1\u5668\uff0c\u5728\u8be5\u670d\u52a1\u5668\u786e\u8ba4\u63a5\u6536\u4e86\u8be5\u56de\u8c03\u540e\u624d\u5c06\u6240\u6709\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\n\n\u56e0\u4e3a\u52a0\u5165\u4e86\u56de\u8c03\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u8fc7\u7a0b\uff0c\u76f8\u6bd4\u7b80\u5355\u4e0a\u4f20\uff0c\u4f7f\u7528\u56de\u8c03\u901a\u77e5\u673a\u5236\u4e00\u822c\u4f1a\u5bfc\u81f4\u5ba2\u6237\u7aef\u82b1\u8d39\u66f4\u591a\u7684\u7b49\u5f85\u65f6\u95f4\u3002\n\n\u5f00\u53d1\u8005\u53ef\u4ee5\u8981\u6c42\u79c1\u6709\u4e91\u5b58\u50a8\u5728\u67d0\u6587\u4ef6\u4e0a\u4f20\u5b8c\u6210\u540e\u5411\u7279\u5b9a\u7684 URL \u53d1\u8d77\u4e00\u4e2a\u56de\u8c03\u8bf7\u6c42\u3002\u79c1\u6709\u4e91\u5b58\u50a8\u4f1a\u5c06\u8be5\u56de\u8c03\u7684\u54cd\u5e94\u5185\u5bb9\u4f5c\u4e3a\u6587\u4ef6\u4e0a\u4f20\u54cd\u5e94\u7684\u4e00\u90e8\u5206\u4e00\u5e76\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u56de\u8c03\u7684\u6d41\u7a0b\u5982\u4e0b\uff1a\n\n\n\u8981\u542f\u7528\u56de\u8c03\u529f\u80fd\uff0c\u4e1a\u52a1\u670d\u52a1\u5668\u5728\u7b7e\u53d1\u4e0a\u4f20\u51ed\u8bc1\u65f6\u9700\u8981\u8bbe\u7f6e\u4e0a\u4f20\u7b56\u7565 (PutPolicy)\u4e2d\u7684 callbackUrl \u548c callbackBody \u5b57\u6bb5\u3002\n\n\n\n## \u56de\u8c03\u5730\u5740\n\n\u901a\u8fc7\u8bbe\u5b9a\u4e0a\u4f20\u7b56\u7565\u4e2d\u7684 callbackUrl \u5b57\u6bb5\u4e3a\u4e00\u4e2a\u6709\u6548\u7684\u5730\u5740\uff0c\u5373\u53ef\u8ba9\u79c1\u6709\u4e91\u5b58\u50a8\u5728\u6587\u4ef6\u4e0a\u4f20\u5b8c\u6210\u540e\u5411\u8be5\u5730\u5740\u53d1\u8d77\u56de\u8c03\u8bf7\u6c42\u3002\u8be5\u5730\u5740\u53ef\u4ee5\u662f\u4e00\u4e2a HTTP \u6216\u8005 HTTPS \u7684 URL\uff0c\u5141\u8bb8\u516c\u7f51\u8bbf\u95ee\u3002\n\n\u5982\u679c\u9700\u8981\u4f20\u9012\u81ea\u5b9a\u4e49\u7684\u8bf7\u6c42\u5185\u5bb9\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8003\u8651\u914d\u5408\u4f7f\u7528\u4e0a\u4f20\u7b56\u7565\u4e2d\u7684 callbackBody \u5b57\u6bb5\u3002\u5982\u679c\u53ea\u6709 callbackUrl \u800c\u6ca1\u6709 callbackBody\uff0c\u56de\u8c03\u670d\u52a1\u5668\u6536\u5230\u7684\u8bf7\u6c42\u5185\u5bb9\u5c06\u4e3a\u7a7a\u3002\n\n\n\n## \u56de\u8c03\u5185\u5bb9\n\n\u540c\u666e\u901a\u5ba2\u6237\u7aef\u76f4\u4f20\u548c\u91cd\u5b9a\u5411\u4e0a\u4f20\u4e00\u6837\uff0c\u7528\u6237\u4e5f\u53ef\u4ee5\u63a7\u5236\u56de\u8c03\u4e2d\u4f20\u9012\u5230\u5ba2\u6237\u56de\u8c03\u670d\u52a1\u5668\u7684\u53cd\u9988\u4fe1\u606f\u3002callbackBody \u7684\u683c\u5f0f\u5982\u4e0b\uff1a\n\n```\n<item>=(<magicvar>|<xvar>)[&<item>=(<magicvar>|<xvar>)...]\n```\n\n\u4e00\u4e2a\u5178\u578b\u7684 callbackBody \u8bbe\u7f6e\u5982\u4e0b\uff08\u5185\u5bb9\u7ecf\u8fc7\u683c\u5f0f\u5316\u65b9\u4fbf\u9605\u8bfb\uff09\uff1a\n\n```\nput_policy = '{\n ...\n \"callbackBody\" : \"name=$(fname)&\n hash=$(etag)&\n location=$(x:location)&\n price=$(x:price)&\n uid=123\"\n ...\n}'\n```\n\n\u4e0a\u9762\u7684 callbackBody \u793a\u4f8b\u4e2d\uff0c\u6df7\u5408\u4f7f\u7528\u4e86\u9b54\u6cd5\u53d8\u91cf name\u3001hash\uff0c\u81ea\u5b9a\u4e49\u53d8\u91cf location\u3001price \u53ca\u81ea\u5b9a\u4e49\u5e38\u91cf uid\u3002 \u5047\u8bbe\u5e94\u7528\u5ba2\u6237\u7aef\u53d1\u51fa\u4e86\u5982\u4e0b\u7684\u4e0a\u4f20\u8bf7\u6c42\uff1a\n\n```\n<form method=\"post\" action=\"http:\/\/upload.qiniup.com\/\" enctype=\"multipart\/form-data\">\n <input name=\"key\" type=\"hidden\" value=\"sunflower.jpg\">\n <input name=\"x:location\" value=\"Shanghai\">\n <input name=\"x:price\" value=\"1500.00\">\n <input name=\"token\" type=\"hidden\" value=\"...\">\n <input name=\"file\" type=\"file\" \/>\n<\/form>\n```\n\n\u5176\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u9001\u4e86\u81ea\u5b9a\u4e49\u53d8\u91cf\u7684\u503c x:location = Shanghai \u548c x:price = 1500.00\uff0c\u79c1\u6709\u4e91\u5b58\u50a8\u5c06\u6839\u636e\u4e0a\u4f20\u8d44\u6e90\u7684\u5b9e\u9645\u60c5\u51b5\u586b\u5199\u9b54\u6cd5\u53d8\u91cf $(fname) \u548c $(etag) \u7684\u503c\u3002\n\n\u5b8c\u6210\u4e0a\u4f20\u540e\uff0c\u79c1\u6709\u4e91\u5b58\u50a8\u4fbf\u4f1a\u6784\u9020\u51fa\u5982\u4e0b\u7684\u56de\u8c03\u4fe1\u606f\uff08\u5185\u5bb9\u7ecf\u8fc7\u683c\u5f0f\u5316\u65b9\u4fbf\u9605\u8bfb\uff09\uff1a\n\n```\nname=sunflower.jpg&\nhash=Fn6qeQi4VDLQ347NiRm- \\\nRlQx_4O2&\nlocation=Shanghai&\nprice=1500.00&\nuid=123\n```\n\n\u79c1\u6709\u4e91\u5b58\u50a8\u5c06\u8fd9\u7ec4\u6570\u636e\u4f5c\u4e3a\u8bf7\u6c42 Body \u53d1\u9001\u81f3\u7528\u6237\u6307\u5b9a\u7684\u56de\u8c03\u670d\u52a1\u5668\uff0c\u8bf7\u6c42\u65b9\u5f0f\u4e3a POST\u3002\u56de\u8c03\u670d\u52a1\u5668\u5c06\u63a5\u6536\u5230\u4ee5\u4e0b\u683c\u5f0f\u7684\u8bf7\u6c42\u5185\u5bb9\uff1a\n\n```\nPOST \/callback HTTP\/1.1\nContent-Type: application\/x-www-form-urlencoded\nUser-Agent: qiniu go-sdk v6.0.0\nHost: api.examples.com\nAuthorization: QBox iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV:tDK-3f5xF3SJYEAwsll5g=\n\nname=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm- \\\nRlQx_4O2&location=Shanghai&price=1500.00&uid=123\n```\n\u56de\u8c03\u670d\u52a1\u5668\u63a5\u6536\u5230\u56de\u8c03\u8bf7\u6c42\u540e\uff0c\u8d1f\u8d23\u751f\u6210\u79c1\u6709\u4e91\u5b58\u50a8\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u7684\u6570\u636e\uff08json \u683c\u5f0f\uff09\uff0c\u8be5\u6570\u636e\u4f5c\u4e3a\u6b64\u6b21\u56de\u8c03\u8bf7\u6c42\u7684\u54cd\u5e94\u5185\u5bb9\u3002\u5982\u679c\u56de\u8c03\u6210\u529f\uff0c\u56de\u8c03\u670d\u52a1\u5e94\u5bf9\u79c1\u6709\u4e91\u5b58\u50a8\u4f5c\u51fa\u7c7b\u4f3c\u5982\u4e0b\u7684\u54cd\u5e94\uff08**\u6ce8\u610f**\uff1a\u56de\u8c03\u54cd\u5e94\u5185\u5bb9\u7531\u56de\u8c03\u670d\u52a1\u5668\u751f\u6210\uff0c\u4ee5\u4e0b\u4ec5\u4e3a\u793a\u4f8b\uff09\uff1a\n\n```\nHTTP\/1.1 200 OK\nServer: nginx\/1.1.19\nDate: Thu, 19 Dec 2013 06:27:30 GMT\nContent-Type: text\/html\nTransfer-Encoding: chunked\nConnection: keep-alive\nCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\nPragma: no-cache\n\n\n{\"success\":true,\"name\":\"sunflowerb.jpg\"}\n```\n\n\u79c1\u6709\u4e91\u5b58\u50a8\u5c06\u4e0a\u9762\u7684\u56de\u8c03\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\uff0c\u5ba2\u6237\u7aef\u63a5\u6536\u5230\u4ee5\u4e0b\u54cd\u5e94\uff1a\n\n```\nHTTP\/1.1 200 OK\nContent-Type: application\/json\nCache-Control: no-store\nServer: nginx\/1.4.4\nDate: Thu, 19 Dec 2013 08:04:56 GMT\nPragma: no-cache\nX-Log: BDT:4;BDT:2;LBD:13;rs.put:1048;rs-upload.putFile:2514;UP.CB:3088;UP:5603\nX-Reqid: iDYAAPBicOGXLUET\n\n{\"success\":true,\"name\":\"sunflowerb.jpg\"}\n```\n\n\u5982\u679c\u56de\u8c03\u5931\u8d25\uff0c\u5ba2\u6237\u7aef\u4f1a\u6536\u5230 HTTP \u9519\u8bef\u7801 579\uff0c\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u5728 Body \u90e8\u5206\u7ed9\u51fa\uff0c\u5982\u4e0b\u6240\u793a\uff08\u5185\u5bb9\u7ecf\u8fc7\u683c\u5f0f\u5316\u65b9\u4fbf\u9605\u8bfb\uff09\uff1a\n\n```\n{\n \"error\":\"{\n \"callback_url\":\"<callbackUrl>\",\n \"callback_bodyType\":\"<callbackBodyType>\",\n \"callback_body\":\"<callbackBody>\",\n \"token\":\"<Token>\",\n \"err_code\":<\u56de\u8c03\u9519\u8bef\u7801>,\n \"error\":\"<\u56de\u8c03\u9519\u8bef\u4fe1\u606f>\",\n \"hash\":\"Fn6qeQi4VDLQ347NiRm-RlQx_4O2\",\n \"key\":\"sunflower.jpg\"\n }\"\n}\n```\n\n\u5982\u679c\u56de\u8c03\u670d\u52a1\u5668\u8fd4\u56de\u5982\u4e0b\u6240\u793a\u7684 Json \u683c\u5f0f\u7684\u9519\u8bef\u5185\u5bb9\uff1a\n\n```\n{\n \"error\":\"<\u9519\u8bef\u4fe1\u606f>\"\n}\n```\n\n\u5e76\u4e14\u8bbe\u7f6e Content-Type \u4e3a application\/json\uff0c\u5219\u4e1a\u52a1\u7aef\u80fd\u89e3\u6790\u51fa <\u9519\u8bef\u4fe1\u606f> \u5e76\u586b\u5165 <\u56de\u8c03\u9519\u8bef\u4fe1\u606f> \u5b57\u6bb5\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u9519\u8bef\u4fe1\u606f\u9700\u8981\u662fString\u683c\u5f0f\uff0c\u5efa\u8bae\u53ef\u4ee5\u662fquery\u7684\u65b9\u5f0f\uff0c\u5982code=400&message='no hedaer'\n\n\n\n## \u5b89\u5168\u6027\n\n\u7531\u4e8e\u56de\u8c03\u5730\u5740\u662f\u516c\u7f51\u53ef\u4efb\u610f\u8bbf\u95ee\u7684\uff0c\u90a3\u5982\u4f55\u786e\u8ba4\u56de\u8c03\u662f\u5408\u6cd5\u7684\u5462?\n\n\u79c1\u6709\u4e91\u5b58\u50a8\u5728\u56de\u8c03\u65f6\u4f1a\u5bf9\u8bf7\u6c42\u6570\u636e\u7b7e\u540d\uff0c\u5e76\u5c06\u7ed3\u679c\u5305\u542b\u5728\u8bf7\u6c42\u5934 Authorization \u5b57\u6bb5\u4e2d\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a\n\n```\nAuthorization:QBox iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV:tDK-3f5xF3SJYEAwsll5g=\n```\n\n\u5176\u4e2d QBox \u4e3a\u56fa\u5b9a\u503c\uff0c*iN7Ngw...dCV* \u4e3a\u7528\u6237\u7684 Accesskey\uff0c*tDK-3f...5g=* \u4e3a\u7b7e\u540d\u7ed3\u679c encoded_data\u3002\n\n\u56de\u8c03\u670d\u52a1\u5668\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u9a8c\u8bc1\u5176\u5408\u6cd5\u6027\uff1a\n\n- \u83b7\u53d6 Authorization \u5b57\u6bb5\u4e2d\u7684\u7b7e\u540d\u7ed3\u679c encoded_data\n- \u6839\u636e Accesskey \u9009\u53d6\u6b63\u786e\u7684 SecretKey\n- \u83b7\u53d6\u660e\u6587 data = Request.URL.Path +\"\\n\" +Request.Body\uff0c\u90e8\u5206\u8bed\u8a00\u6216\u6846\u67b6\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\u8bf7\u6c42 body \u7684\u539f\u59cb\u6570\u636e\uff0c\u5728\u81ea\u884c\u62fc\u63a5\u65f6\u5e94\u5f53\u6ce8\u610f\uff0cbody \u4e2d\u7684\u6570\u636e\u662f\u7ecf\u8fc7URL \u5b89\u5168\u7684 Base64 \u7f16\u7801\u7684\u3002\n- \u91c7\u7528 HMAC-SHA1 \u7b7e\u540d\u7b97\u6cd5\uff0c\u5bf9\u660e\u6587 data \u7b7e\u540d\uff0c\u5bc6\u94a5\u4e3a SecretKey\uff0c\u6bd4\u8f83\u7b7e\u540d\u7ed3\u679c\u662f\u5426\u4e0e Authorization \u5b57\u6bb5\u4e2d\u7684 encoded_data \u5b57\u6bb5\u76f8\u540c\uff0c\u5982\u76f8\u540c\u5219\u8868\u660e\u8fd9\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u56de\u8c03\u8bf7\u6c42\u3002\n\n**\u6ce8\u610f**\uff1a\u4e1a\u52a1\u7aef\u670d\u52a1\u5668\u56de\u8c03\u9274\u6743\u7684Content-Type\u7c7b\u578b\u5e94\u8be5\u4e0e\u4e0a\u4f20\u7b56\u7565\u4e2d\u6307\u5b9a\u7684callbackBodyType\u76f8\u540c\uff0c\u9ed8\u8ba4\u4e3a application\/x-www-form-urlencoded\uff0c\u5f53 Content-Type \u4e3a application\/x-www-form-urlencoded \u65f6\uff0c\u7b7e\u540d\u5185\u5bb9\u5fc5\u987b\u5305\u62ec\u8bf7\u6c42\u5185\u5bb9\u3002\u5f53 Content-Type \u4e3a application\/json \u65f6\uff0c\u7b7e\u540d\u5185\u5bb9\u4e0d\u5305\u62ec\u8bf7\u6c42\u5185\u5bb9\u3002\u7b7e\u540d\u65b9\u5f0f\u53ef\u53c2\u8003 Authorization\n\n\u4ee5 PHP \u8bed\u8a00\u4e3a\u4f8b\uff0c\u9a8c\u8bc1\u4ee3\u7801\u5982\u4e0b\uff1a\n![](https:\/\/tp2lravq.hk03.1112oss.com\/20230712093905rewii4pkb7jadsq83kcc7acb0v8c5e8t.png)\n\n**\u6ce8\u610f**\uff1a\u5982\u679c\u56de\u8c03\u6570\u636e\u6709\u7528\u6237\u7684\u654f\u611f\u6570\u636e\uff0c\u5efa\u8bae\u56de\u8c03\u5730\u5740\u4f7f\u7528 HTTPS \u534f\u8bae\u3002"}