Commit 823c5ce280605e5b0460079e193973c0ab6296ab
1 parent
7f75e0ff
Exists in
master
1. 接口功能实现。
Showing
6 changed files
with
170 additions
and
11 deletions
Show diff stats
app-wx/modules/check/controllers/DefaultController.php
... | ... | @@ -101,11 +101,16 @@ class DefaultController extends BaseController |
101 | 101 | $e->message = ''; |
102 | 102 | $wechat = WxHelper::getWxPHPSDK(); |
103 | 103 | $uploadFile = $this->request->post('service_id'); |
104 | + $uuid = $this->request->post('uuid'); | |
104 | 105 | if (empty($uploadFile)) { |
105 | 106 | $e->message = '请上传商品图片或视频!'; |
106 | 107 | return $this->renderJson($e); |
107 | 108 | } |
108 | - $filename = $this->saveWxImgToRemoveServer($wechat, $uploadFile); | |
109 | + if (empty($uuid)) { | |
110 | + $e->message = '缺少必要参数!'; | |
111 | + return $this->renderJson($e); | |
112 | + } | |
113 | + $filename = $this->saveWxImgToRemoveServer($wechat, $uploadFile, $uuid); | |
109 | 114 | if (!$filename) { |
110 | 115 | $e->message = '保存失败!'; |
111 | 116 | return $this->renderJson($e); |
... | ... | @@ -123,7 +128,7 @@ class DefaultController extends BaseController |
123 | 128 | * @return bool|string 返回保存到数据库里面的文件名称是的带URL的,同时会把图片传到阿里云的图片服务器上面 |
124 | 129 | * $type 这个是类型,根据图片是头像还是身份证来存放,$stat_path 必须根据$type 而改变 |
125 | 130 | */ |
126 | - private function saveWxImgToRemoveServer($wechat, $tr = '') | |
131 | + private function saveWxImgToRemoveServer($wechat, $tr = '', $uuid) | |
127 | 132 | { |
128 | 133 | if (empty($tr)) { |
129 | 134 | return false; |
... | ... | @@ -151,7 +156,7 @@ class DefaultController extends BaseController |
151 | 156 | } |
152 | 157 | } |
153 | 158 | $user_id = $userId = $this->getUserId(); |
154 | - $stat_path = ImageManager::getSmartCheckImgPath($user_id, 'smart_' . $tt . md5($tr)); | |
159 | + $stat_path = ImageManager::getSmartCheckImgPath($user_id, $uuid); | |
155 | 160 | ImageManager::add($saveFilePath, $stat_path); |
156 | 161 | |
157 | 162 | return $stat_path; | ... | ... |
app-wx/modules/smart/controllers/DefaultController.php
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | namespace app\wx\modules\smart\controllers; |
4 | 4 | |
5 | 5 | use Yii; |
6 | +use common\helpers\CheckActiveHelper; | |
6 | 7 | use common\helpers\ImageManager; |
7 | 8 | use common\helpers\ImageUtils; |
8 | 9 | use common\helpers\WxHelper; |
... | ... | @@ -111,11 +112,38 @@ class DefaultController extends BaseController |
111 | 112 | // 保存图片到OSS |
112 | 113 | $dir = Yii::getAlias('@app/wx') . "/web/tmp/"; |
113 | 114 | $img_path = $dir . $fileData; |
114 | - // @todo 校验激活 | |
115 | + | |
116 | + // 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活 | |
117 | + $checkResult = CheckActiveHelper::getAppActivate($uuid); | |
118 | + $activeResult = false; | |
119 | + if ($checkResult) { | |
120 | + //success:激活成功 fail:激活失败,无效标签 activated:已激活过 | |
121 | + if (isset($checkResult["status"]) && "success" == $checkResult["status"]) { | |
122 | + $activeResult = true; | |
123 | + } else if (isset($checkResult["status"]) && "fail" == $checkResult["status"]) { | |
124 | + $e->msg = '该二维码无效'; | |
125 | + return $this->renderJson($e); | |
126 | + } else if (isset($checkResult["status"]) && "activated" == $checkResult["status"]) { | |
127 | + $e->message = '该二维码已激活'; | |
128 | + return $this->renderJson($e); | |
129 | + } | |
130 | + } | |
131 | + | |
132 | + if (!$activeResult) { | |
133 | + $e->message = '该二维码激活失败'; | |
134 | + return $this->renderJson($e); | |
135 | + } | |
136 | + | |
115 | 137 | $newPath = ImageManager::getSmartImgPath($userId, $suffix); |
116 | 138 | |
117 | 139 | ImageManager::add($img_path, $newPath); |
118 | 140 | |
141 | + if ($suffix == "mp4") { | |
142 | + $productVedioPath = $newPath; | |
143 | + } else { | |
144 | + $productImagePath = $newPath; | |
145 | + } | |
146 | + | |
119 | 147 | $saveData = [ |
120 | 148 | "user_mp_id" => $userId, |
121 | 149 | "leave_message" => $content, |
... | ... | @@ -256,7 +284,7 @@ class DefaultController extends BaseController |
256 | 284 | $e->message = '缺少必要参数!'; |
257 | 285 | return $this->renderJson($e); |
258 | 286 | } |
259 | - // @todo 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活 | |
287 | + // 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活 | |
260 | 288 | $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]); |
261 | 289 | if (empty($hasRecord)) { |
262 | 290 | $e->success = 0; | ... | ... |
app-wx/web/dist/js/check-app.js
1 | -define("check-app",["mk7/app"],function(n){var e=Dom7,t=function(){var n=e(".ui-loading-block");0==n.length&&(e(".view-main").html('<div class="ui-loading-block" id="ui-loading"><div class="ui-loading-cnt"><div class="spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div><div id="loader-inner"><p></p></div> </div> </div>'),window.waitingTime=1e4,window.loaderTimer&&clearTimeout(window.loaderTimer),window.loaderTimer=setTimeout(function(){var n=document.getElementById("loader-inner"),e=document.createElement("p");e.className="notice",n&&(e.innerHTML='加载速度太慢?试试<a class="link" href="#" onclick="javascript:location.reload();return false;">重新加载</a>',n.appendChild(e))},window.waitingTime))},o=!0;return n.name="check",n.routes={index:function(){return o=!1,t(),n.runController("index")},"*":function(){return o=!1,t(),n.runController("index")},"scan-count/:uuid/:scancount":function(e,i){return o=!1,t(),n.runController("scan-count",{uuid:e,scancount:i})},"warning/:uuid":function(e){return o=!1,t(),n.runController("warning",{uuid:e})},"submit/:uuid":function(e){return o=!1,t(),n.runController("submit",{uuid:e})},"error/:uuid":function(e){return o=!1,t(),n.runController("error",{uuid:e})},"success/:uuid":function(e){return o=!1,t(),n.runController("success",{uuid:e})},"info/:uuid/:number_code":function(e,i){return o=!1,t(),n.runController("info",{uuid:e,number_code:i})}},n}),define("check/error-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7;Template7;return n.run=function(){var n=this;n.setPageTitle("验证结果"),n.render()},n.bindEvents=function(){c(".back-button").click(function(){window.history.go(-1)})},n}),define("check/index-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,1),a=0,u=2,s=0;return n.run=function(){var n=this;n.setPageTitle("验证标签"),i.config({debug:!1,appId:window.$site.appid,timestamp:window.$site.timestamp,nonceStr:window.$site.noncestr,signature:window.$site.signature,jsApiList:["openLocation","getLocation","scanQRCode"]}),n.scanQrcode(),n.render()},n.bindEvents=function(){var n=this;c(".scan-button").click(function(){n.scanQrcode()})},n.scanQrcode=function(){var n=this;i.ready(function(){i.scanQRCode({needResult:1,desc:"scanQRCode desc",success:function(o){var i=o.resultStr,d=c.parseUrlQuery(i);if(null!=d&&void 0!==d&&null!=d.uuid&&void 0!==d.uuid){var d=d.uuid.split("@"),l=e.to("smart#enter/"+d[0]),m=e.to("check#scan-count/"+d[0]+"/"+s),f=e.to("check#warning/"+d[0]);c.ajax({method:"POST",url:e.to("check/default/check-active"),data:{uuid:d[0]},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){s=n.scan_count,m=e.to("check#scan-count/"+d[0]+"/"+s),n.success==r?window.location.href=m:n.success==a?window.location.href=l:n.success==u?window.location.href=f:window.location.href=f},error:function(n){},complete:function(e){n.hideIndicator()}})}else t.toast({content:"请扫描智能防伪二维码"})}})})},n}),define("check/info-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7;Template7;return n.run=function(){var n=this;n.setPageTitle("验证结果"),n.loadData(n.params.uuid,n.params.number_code)},n.bindEvents=function(){c(".back-button").click(function(){window.history.go(-1)})},n.loadData=function(n,o){var i=this;c.ajax({method:"POST",url:e.to("check/default/get-info"),data:{uuid:n,number_code:o},dataType:"json",beforeSend:function(){i.showIndicator()},success:function(n){try{n.success?i.render(n.data):t.toast({content:n.message,closeDelay:3e3})}catch(e){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(n){i.hideIndicator()}})},n}),define("check/scan-count-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,0),a="";return n.run=function(){var n=this;r=parseInt(n.params.scancount),a=n.params.uuid,n.setPageTitle("验证标签"),n.render(),c(".count-num").html(r)},n.bindEvents=function(){c(".scan-button").click(function(){""!=a&&void 0!=a?window.location.href=e.to("check#submit/"+a):window.location.href=e.to("check#index")})},n}),define("check/submit-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,"");return n.run=function(){var n=this;r=n.params.uuid,n.setPageTitle("验证标签"),i.config({debug:!1,appId:window.$site.appid,timestamp:window.$site.timestamp,nonceStr:window.$site.noncestr,signature:window.$site.signature,jsApiList:["chooseImage","previewImage","uploadImage","getLocalImgData"]}),n.render()},n.bindEvents=function(){var n=this;c(".scan-image").click(function(){n.uploadImg(c(this))}),c(".scan-button").click(function(){var o=c(".scan-image").attr("data");return t.isEmpty(o)?(t.toast({content:"请拍照文件上传后再试!"}),!1):void c.ajax({method:"POST",url:e.to("check/default/check-actived"),data:{upload_file:o},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=e.to("check#success/"+r):window.location.href=e.to("check#error/"+r)}catch(o){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(e){n.hideIndicator()}})})},n.uploadImg=function(n){var e=this;i.ready(function(){i.chooseImage({count:1,sizeType:["compressed"],sourceType:["album","camera"],success:function(t){t.localIds.length>0&&e.upload(t.localIds,n)}})})},n.upload=function(n,o){var r=this;return void 0==n[0]?"":void i.uploadImage({localId:n[0],isShowProgressTips:1,success:function(n){c.ajax({method:"POST",url:e.to("check/default/update-serviceid"),data:{service_id:n.serverId},dataType:"json",beforeSend:function(){r.showIndicator()},success:function(n){try{if(n.success){var e=n.img_path;o.attr("data",e),o.attr("src",n.show_path)}else t.toast({content:n.message,closeDelay:3e3})}catch(i){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(n){r.hideIndicator()}})},fail:function(n){r.app.alert(JSON.stringify(n))}})},n}),define("check/success-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,"");return n.run=function(){var n=this;r=n.params.uuid,n.setPageTitle("验证结果"),n.render()},n.bindEvents=function(){var n=this;c(".btn-submit").click(function(){var o=c(".input-num").val();return t.isEmpty(o)?(t.toast({content:"请填写提取码"}),c(".input-num").focus(),!1):t.isEmpty(r)?(t.toast({content:"缺少必要参数请退出重试"}),!1):void c.ajax({method:"POST",url:e.to("check/default/get-info"),data:{uuid:r,number_code:o},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=e.to("check#info/"+r+"/"+o):t.toast({content:n.message,closeDelay:3e3})}catch(i){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(e){n.hideIndicator()}})})},n}),define("check/warning-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,"");return n.run=function(){var n=this;r=n.params.uuid,n.setPageTitle("验证标签"),n.render()},n.bindEvents=function(){c(".scan-jump-button").click(function(){""!=r&&void 0!=r?window.location.href=e.to("smart#enter/"+r):window.location.href=e.to("check#index")})},n}); | |
2 | 1 | \ No newline at end of file |
2 | +define("check-app",["mk7/app"],function(n){var e=Dom7,t=function(){var n=e(".ui-loading-block");0==n.length&&(e(".view-main").html('<div class="ui-loading-block" id="ui-loading"><div class="ui-loading-cnt"><div class="spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div><div id="loader-inner"><p></p></div> </div> </div>'),window.waitingTime=1e4,window.loaderTimer&&clearTimeout(window.loaderTimer),window.loaderTimer=setTimeout(function(){var n=document.getElementById("loader-inner"),e=document.createElement("p");e.className="notice",n&&(e.innerHTML='加载速度太慢?试试<a class="link" href="#" onclick="javascript:location.reload();return false;">重新加载</a>',n.appendChild(e))},window.waitingTime))},o=!0;return n.name="check",n.routes={index:function(){return o=!1,t(),n.runController("index")},"*":function(){return o=!1,t(),n.runController("index")},"scan-count/:uuid/:scancount":function(e,i){return o=!1,t(),n.runController("scan-count",{uuid:e,scancount:i})},"warning/:uuid":function(e){return o=!1,t(),n.runController("warning",{uuid:e})},"submit/:uuid":function(e){return o=!1,t(),n.runController("submit",{uuid:e})},"error/:uuid":function(e){return o=!1,t(),n.runController("error",{uuid:e})},"success/:uuid":function(e){return o=!1,t(),n.runController("success",{uuid:e})},"info/:uuid/:number_code":function(e,i){return o=!1,t(),n.runController("info",{uuid:e,number_code:i})}},n}),define("check/error-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7;Template7;return n.run=function(){var n=this;n.setPageTitle("验证结果"),n.render()},n.bindEvents=function(){c(".back-button").click(function(){window.history.go(-1)})},n}),define("check/index-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,1),a=0,u=2,s=0;return n.run=function(){var n=this;n.setPageTitle("验证标签"),i.config({debug:!1,appId:window.$site.appid,timestamp:window.$site.timestamp,nonceStr:window.$site.noncestr,signature:window.$site.signature,jsApiList:["openLocation","getLocation","scanQRCode"]}),n.scanQrcode(),n.render()},n.bindEvents=function(){var n=this;c(".scan-button").click(function(){n.scanQrcode()})},n.scanQrcode=function(){var n=this;i.ready(function(){i.scanQRCode({needResult:1,desc:"scanQRCode desc",success:function(o){var i=o.resultStr,d=c.parseUrlQuery(i);if(null!=d&&void 0!==d&&null!=d.uuid&&void 0!==d.uuid){var d=d.uuid.split("@"),l=e.to("smart#enter/"+d[0]),m=e.to("check#scan-count/"+d[0]+"/"+s),f=e.to("check#warning/"+d[0]);c.ajax({method:"POST",url:e.to("check/default/check-active"),data:{uuid:d[0]},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){s=n.scan_count,m=e.to("check#scan-count/"+d[0]+"/"+s),n.success==r?window.location.href=m:n.success==a?window.location.href=l:n.success==u?window.location.href=f:window.location.href=f},error:function(n){},complete:function(e){n.hideIndicator()}})}else t.toast({content:"请扫描智能防伪二维码"})}})})},n}),define("check/info-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7;Template7;return n.run=function(){var n=this;n.setPageTitle("验证结果"),n.loadData(n.params.uuid,n.params.number_code)},n.bindEvents=function(){c(".back-button").click(function(){window.history.go(-1)})},n.loadData=function(n,o){var i=this;c.ajax({method:"POST",url:e.to("check/default/get-info"),data:{uuid:n,number_code:o},dataType:"json",beforeSend:function(){i.showIndicator()},success:function(n){try{n.success?i.render(n.data):t.toast({content:n.message,closeDelay:3e3})}catch(e){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(n){i.hideIndicator()}})},n}),define("check/scan-count-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,0),a="";return n.run=function(){var n=this;r=parseInt(n.params.scancount),a=n.params.uuid,n.setPageTitle("验证标签"),n.render(),c(".count-num").html(r)},n.bindEvents=function(){c(".scan-button").click(function(){""!=a&&void 0!=a?window.location.href=e.to("check#submit/"+a):window.location.href=e.to("check#index")})},n}),define("check/submit-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,"");return n.run=function(){var n=this;r=n.params.uuid,n.setPageTitle("验证标签"),i.config({debug:!1,appId:window.$site.appid,timestamp:window.$site.timestamp,nonceStr:window.$site.noncestr,signature:window.$site.signature,jsApiList:["chooseImage","previewImage","uploadImage","getLocalImgData"]}),n.render()},n.bindEvents=function(){var n=this;c(".scan-image").click(function(){n.uploadImg(c(this))}),c(".scan-button").click(function(){var o=c(".scan-image").attr("data");return t.isEmpty(o)?(t.toast({content:"请拍照文件上传后再试!"}),!1):void c.ajax({method:"POST",url:e.to("check/default/check-actived"),data:{upload_file:o,uuid:r},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=e.to("check#success/"+r):window.location.href=e.to("check#error/"+r)}catch(o){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(e){n.hideIndicator()}})})},n.uploadImg=function(n){var e=this;i.ready(function(){i.chooseImage({count:1,sizeType:["compressed"],sourceType:["album","camera"],success:function(t){t.localIds.length>0&&e.upload(t.localIds,n)}})})},n.upload=function(n,o){var a=this;return void 0==n[0]?"":void i.uploadImage({localId:n[0],isShowProgressTips:1,success:function(n){c.ajax({method:"POST",url:e.to("check/default/update-serviceid"),data:{service_id:n.serverId,uuid:r},dataType:"json",beforeSend:function(){a.showIndicator()},success:function(n){try{if(n.success){var e=n.img_path;o.attr("data",e),o.attr("src",n.show_path)}else t.toast({content:n.message,closeDelay:3e3})}catch(i){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(n){a.hideIndicator()}})},fail:function(n){a.app.alert(JSON.stringify(n))}})},n}),define("check/success-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,"");return n.run=function(){var n=this;r=n.params.uuid,n.setPageTitle("验证结果"),n.render()},n.bindEvents=function(){var n=this;c(".btn-submit").click(function(){var o=c(".input-num").val();return t.isEmpty(o)?(t.toast({content:"请填写提取码"}),c(".input-num").focus(),!1):t.isEmpty(r)?(t.toast({content:"缺少必要参数请退出重试"}),!1):void c.ajax({method:"POST",url:e.to("check/default/get-info"),data:{uuid:r,number_code:o},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=e.to("check#info/"+r+"/"+o):t.toast({content:n.message,closeDelay:3e3})}catch(i){t.toast({content:"出错",closeDelay:3e3})}},error:function(n){t.toast({content:"提交出错,请联系系统管理员"})},complete:function(e){n.hideIndicator()}})})},n}),define("check/warning-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,e,t,o,i){var n=new n,c=Dom7,r=(Template7,"");return n.run=function(){var n=this;r=n.params.uuid,n.setPageTitle("验证标签"),n.render()},n.bindEvents=function(){c(".scan-jump-button").click(function(){""!=r&&void 0!=r?window.location.href=e.to("smart#enter/"+r):window.location.href=e.to("check#index")})},n}); | |
3 | 3 | \ No newline at end of file | ... | ... |
app-wx/web/src/js/check/submit-controller.js
... | ... | @@ -45,7 +45,7 @@ define( |
45 | 45 | $$.ajax({ |
46 | 46 | method : "POST", |
47 | 47 | url: url.to('check/default/check-actived'), |
48 | - data : {upload_file: uploadFile}, | |
48 | + data : {upload_file: uploadFile, uuid: uuid}, | |
49 | 49 | dataType : "json", |
50 | 50 | beforeSend : function(){ |
51 | 51 | me.showIndicator(); |
... | ... | @@ -100,7 +100,7 @@ define( |
100 | 100 | $$.ajax({ |
101 | 101 | method : "POST", |
102 | 102 | url: url.to('check/default/update-serviceid'), |
103 | - data : {service_id:res.serverId}, | |
103 | + data : {service_id:res.serverId, uuid: uuid}, | |
104 | 104 | dataType : "json", |
105 | 105 | beforeSend : function(){ |
106 | 106 | me.showIndicator(); | ... | ... |
... | ... | @@ -0,0 +1,126 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace common\helpers; | |
4 | + | |
5 | +use Exception; | |
6 | +use function curl_init; | |
7 | +use function curl_setopt; | |
8 | +use function stripos; | |
9 | +use function http_build_query; | |
10 | +use function curl_exec; | |
11 | +use function curl_getinfo; | |
12 | +use function in_array; | |
13 | +use function curl_close; | |
14 | +use function json_decode; | |
15 | +use function file_get_contents; | |
16 | +use function base64_encode; | |
17 | + | |
18 | +class CheckActiveHelper | |
19 | +{ | |
20 | + const CHECK_URL = 'http://zhoundlee.com/app_qrv'; | |
21 | + | |
22 | + const ACTIVE_URL = 'http://zhoundlee.com/app_activate'; | |
23 | + | |
24 | + /** | |
25 | + * 调用智纹保校验接口 | |
26 | + * @param $img 图片内容 file 是 用户上传的图片,文件类型(二进制图片数据) | |
27 | + * @param $fileName 图片名称 string 是 用户上传的图片原始名字 | |
28 | + * 格式: IMG_防伪标签uuid_时间戳.jpg 注意: 1) 中间两个下划线 _ 不可省略 2) 微信扫码出来的uuid参数中的版本号部分去掉@v1.0 | |
29 | + * @return bool|string "" | |
30 | + * content object 内容 | |
31 | + * status string 状态码【待定】(authentic:正品 fake:假货 其他状态码:请闵总帮忙补充) | |
32 | + * imgUrl file 返回的图片状态 备注:请返回完整的URL路径,例如:http://check1.bosch-smartlife.com/images/success.png | |
33 | + */ | |
34 | + public static function checkAppQrv($imageFullPath, $fileName) | |
35 | + { | |
36 | + try { | |
37 | + $curl = curl_init(); | |
38 | + curl_setopt($curl, CURLOPT_URL, self::CHECK_URL); | |
39 | + | |
40 | + // 获取图片内容 | |
41 | + $fp = file_get_contents($imageFullPath); // 获取图片的二进制数据 | |
42 | + $image = base64_encode($fp); //图片二进制数据base64编码 | |
43 | + // 设置post数据 | |
44 | + $post_data = array( | |
45 | + "img" => $image, | |
46 | + "fileName" => $fileName | |
47 | + ); | |
48 | + // 如果是https协议 | |
49 | + if (stripos(self::CHECK_URL, "https://") !== FALSE) { | |
50 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | |
51 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); | |
52 | + //CURL_SSLVERSION_TLSv1 | |
53 | + curl_setopt($curl, CURLOPT_SSLVERSION, 1); | |
54 | + } | |
55 | + // 通过POST方式提交 | |
56 | + curl_setopt($curl, CURLOPT_POST, true); | |
57 | + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); | |
58 | + | |
59 | + // 超时时间 | |
60 | + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); | |
61 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); | |
62 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
63 | + // 返回内容 | |
64 | + $callbcak = curl_exec($curl); | |
65 | + //http状态码 | |
66 | + $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | |
67 | + // 处理返回状态 | |
68 | + if (in_array($httpCode, array(400, 403))) | |
69 | + return ""; | |
70 | + // 关闭,释放资源 | |
71 | + curl_close($curl); | |
72 | + //返回内容JSON_DECODE | |
73 | + return json_decode($callbcak, true); | |
74 | + } catch (Exception $e) { | |
75 | + return false; | |
76 | + } | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * 防伪标签的激活 | |
81 | + * @param $uuid string 是 防伪标签uuid | |
82 | + * @return mixed|string {"status": "success"} | |
83 | + * 状态码:success:激活成功 fail:激活失败,无效标签 activated:已激活过 | |
84 | + */ | |
85 | + public static function getAppActivate($uuid) | |
86 | + { | |
87 | + try { | |
88 | + $curl = curl_init(); | |
89 | + curl_setopt($curl, CURLOPT_URL, self::ACTIVE_URL); | |
90 | + /*curl_setopt($curl, CURLOPT_HTTPHEADER, array ( | |
91 | + 'Authorization:APPCODE '.self::APPCODE_IMAGE | |
92 | + ));*/ | |
93 | + //设置post数据 | |
94 | + $post_data = array( | |
95 | + "uuid" => $uuid | |
96 | + );; | |
97 | + //如果是https协议 | |
98 | + if (stripos(self::ACTIVE_URL, "https://") !== FALSE) { | |
99 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | |
100 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); | |
101 | + curl_setopt($curl, CURLOPT_SSLVERSION, 1); | |
102 | + } | |
103 | + //通过POST方式提交 | |
104 | + curl_setopt($curl, CURLOPT_POST, true); | |
105 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); | |
106 | + | |
107 | + //超时时间 | |
108 | + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); | |
109 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); | |
110 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
111 | + //返回内容 | |
112 | + $callbcak = curl_exec($curl); | |
113 | + //http状态码 | |
114 | + $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); | |
115 | + //状态处理 | |
116 | + if (in_array($httpCode, array(400, 403))) | |
117 | + return ""; | |
118 | + //关闭,释放资源 | |
119 | + curl_close($curl); | |
120 | + //返回内容JSON_DECODE | |
121 | + return json_decode($callbcak, true); | |
122 | + } catch (Exception $e) { | |
123 | + return false; | |
124 | + } | |
125 | + } | |
126 | +} | |
0 | 127 | \ No newline at end of file | ... | ... |
common/helpers/ImageManager.php
... | ... | @@ -127,15 +127,15 @@ class ImageManager |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | - * 商品图片存储路径: smart/20170509/[userid]/[16位md5加密串].jpg | |
130 | + * 商品图片存储路径: IMG_防伪标签uuid_时间戳.jpg | |
131 | 131 | * @param $userId |
132 | 132 | * @param $suffix 图片后缀, 如'.jpg' |
133 | 133 | * @param $fileName 图片另外的名称,商品图片存储路径 |
134 | 134 | * @return string |
135 | 135 | */ |
136 | - public static function getSmartCheckImgPath($userId, $fileName = '', $suffix = 'jpg') | |
136 | + public static function getSmartCheckImgPath($userId, $uuid = '', $suffix = 'jpg') | |
137 | 137 | { |
138 | - $imageName = md5(time() . $userId . $fileName . self::rand(5)) . '.' . $suffix; | |
138 | + $imageName = "IMG_" . $uuid . "_" . time() . '.' . $suffix; | |
139 | 139 | $basePath = self::$CHECK_ROOT_PATH . date("Ymd") . '/' . $userId; |
140 | 140 | $savePath = $basePath . '/' . $imageName; |
141 | 141 | return $savePath; | ... | ... |