Commit 4daadf17f65822ab69c31b8cf652b48af959d48a

Authored by 曹明
1 parent 48815a7e
Exists in master

1.对接API接口

app-wx/controllers/QrcodeController.php
1 1 <?php
2 2 namespace app\wx\controllers;
3 3  
  4 +use common\helpers\CheckActiveHelper;
  5 +use common\helpers\Log;
4 6 use domain\smart\ScanRecords;
5 7 use domain\smart\SellerInputRecordRepository;
6 8 use Yii;
... ... @@ -41,18 +43,34 @@ class QrcodeController extends BaseController
41 43 $this->jumpError();
42 44 }
43 45 $uuid = $explodArrar[0];
44   - // @todo 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活
45   - $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
46   - if (empty($hasRecord)) {
47   - $this->jumpActive($uuid);
  46 + // @todo 校验UUID是否有效 -2 无效 0 有效未激活 2 有效已激活
  47 + $startTime = microtime(true);
  48 + $result = CheckActiveHelper::getAppCheck($uuid, "");
  49 + $etime=microtime(true);//获取程序执行结束的时间
  50 + $total=$etime-$startTime; //计算差值
  51 + Log::DEBUG("调用检查接口结果:" . json_encode($result) . '执行时间:' . $total . "秒");
  52 + if (isset($result["code"])) {
  53 + if ($result["code"] == 2) {
  54 + $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
  55 + if (empty($hasRecord)) {
  56 + $this->jumpActive($uuid);
  57 + } else {
  58 + // 记录扫码次数
  59 + $scanCount = ScanRecords::updateCount($uuid);
  60 + $scanCount = $scanCount ? $scanCount : 1;
  61 + $this->jumpScanCount($uuid, $scanCount);
  62 + }
  63 + } else if ($result["code"] == 0) {
  64 + // 记录扫码次数
  65 + $scanCount = ScanRecords::updateCount($uuid);
  66 + $scanCount = $scanCount ? $scanCount : 1;
  67 + $this->jumpScanCount($uuid, $scanCount);
  68 + } else {
  69 + $this->jumpError();
  70 + }
48 71 } else {
49   - // 记录扫码次数
50   - $scanCount = ScanRecords::updateCount($uuid);
51   - $scanCount = $scanCount ? $scanCount : 1;
52   - $this->jumpScanCount($uuid, $scanCount);
  72 + $this->jumpError();
53 73 }
54   -
55   -
56 74 }
57 75  
58 76 /**
... ...
app-wx/modules/check/controllers/DefaultController.php
... ... @@ -3,7 +3,9 @@
3 3 namespace app\wx\modules\check\controllers;
4 4  
5 5 use Yii;
  6 +use common\helpers\CheckActiveHelper;
6 7 use common\helpers\ImageManager;
  8 +use common\helpers\Log;
7 9 use common\helpers\WxHelper;
8 10 use domain\smart\ScanRecords;
9 11 use domain\smart\SellerInputRecordRepository;
... ... @@ -37,20 +39,38 @@ class DefaultController extends BaseController
37 39 $e->message = '缺少必要参数!';
38 40 return $this->renderJson($e);
39 41 }
40   - // @todo 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活
41   - $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
42   - if (empty($hasRecord)) {
43   - $e->success = 0;
44   - $e->message = '暂无激活!';
45   - return $this->renderJson($e);
46   - } else {
47   - // 记录扫码次数
48   - $scan_count = ScanRecords::updateCount($uuid);
49   - if ($scan_count) {
50   - $e->scan_count = (int) $scan_count;
  42 + // @todo 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活 (接口:校验UUID是否有效 -2 无效 0 有效未激活 2 有效已激活)
  43 + $result = CheckActiveHelper::getAppCheck($uuid, "");
  44 + Log::DEBUG("扫码调用检查接口CHECK-DEFAULT结果:" . json_encode($result));
  45 + if (isset($result["code"])) {
  46 + if ($result["code"] == 2) {
  47 + // 记录扫码次数
  48 + $scan_count = ScanRecords::updateCount($uuid);
  49 + if ($scan_count) {
  50 + $e->scan_count = (int) $scan_count;
  51 + }
  52 + $e->success = 1;
  53 + $e->message = '已激活';
  54 + } else if ($result["code"] == 0) {
  55 + $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
  56 + if (empty($hasRecord)) {
  57 + $e->success = 0;
  58 + $e->message = '暂无激活!';
  59 + return $this->renderJson($e);
  60 + } else {
  61 + // 记录扫码次数
  62 + $scan_count = ScanRecords::updateCount($uuid);
  63 + if ($scan_count) {
  64 + $e->scan_count = (int) $scan_count;
  65 + }
  66 + $e->success = 1;
  67 + $e->message = '已激活';
  68 + }
  69 + } else {
  70 + $e->success = 2;
  71 + $e->message = '无效二维码!';
  72 + return $this->renderJson($e);
51 73 }
52   - $e->success = 1;
53   - $e->message = '已激活';
54 74 }
55 75 return $this->renderJson($e);
56 76  
... ... @@ -64,28 +84,44 @@ class DefaultController extends BaseController
64 84 {
65 85 $e = new stdClass();
66 86 $e->success = false;
  87 + $e->code = 2;
67 88 $e->scan_count = 0;
68 89 $e->message = "";
69 90 $uploadFile = Yii::$app->request->post("upload_file");
70   - if (empty($uploadFile)) {
  91 + $uuid = Yii::$app->request->post("uuid");
  92 + if (empty($uploadFile) || empty($uuid)) {
71 93 $e->message = '缺少必要参数!';
72 94 return $this->renderJson($e);
73 95 }
  96 + $filename = basename($uploadFile);
74 97 // 获取图片路径
75   - //$uploadFile = ImageManager::getUrl($uploadFile);
  98 + $uploadFile = ImageManager::getUrl($uploadFile);
76 99  
77 100 // @todo 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活
78   - $hasRecord = true;
79   - if (!$hasRecord) {
80   - $e->success = false;
81   - $e->message = '暂无激活!';
  101 + $startTime = microtime(true);
  102 + $result = CheckActiveHelper::checkAppQrv($uploadFile, $filename, ""); // authentic: 正品 fake: 假货 fuzzy: 图片模糊
  103 + $etime=microtime(true);//获取程序执行结束的时间
  104 + $total=$etime-$startTime; //计算差值
  105 + Log::DEBUG("调用检查图片接口结果:" . json_encode($result) . '执行时间:' . $total . "秒" . ",文件名称:" . $filename .", 文件路径:" . $uploadFile);
  106 + if (isset($result["status"])) {
  107 + if ($result["status"] == "authentic") {
  108 + $e->success = true;
  109 + $e->code = 1;
  110 + $e->message = '正品';
  111 + } elseif ($result["status"] == "fuzzy") {
  112 + $e->success = true;
  113 + $e->code = 0;
  114 + $e->message = '图片模糊';
  115 + } else {
  116 + $e->success = false;
  117 + $e->code = 2;
  118 + $e->message = '假货';
  119 + }
82 120 return $this->renderJson($e);
83 121 } else {
84   - $e->success = true;
85   - $e->message = '已激活';
  122 + $e->success = false;
  123 + $e->message = '假货';
86 124 }
87   - return $this->renderJson($e);
88   -
89 125 }
90 126  
91 127 /**
... ...
app-wx/modules/smart/controllers/DefaultController.php
... ... @@ -189,9 +189,13 @@ class DefaultController extends BaseController
189 189 $productVedioPath = "";
190 190  
191 191 // 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活
192   - $checkResult = false;// 测试暂时注释:CheckActiveHelper::getAppActivate($uuid);
  192 + $startTime = microtime(true);
  193 + $checkResult = CheckActiveHelper::getAppActivate($uuid, "");
  194 + $etime=microtime(true);//获取程序执行结束的时间
  195 + $total=$etime-$startTime; //计算差值
  196 + Log::DEBUG("调用激活接口结果:" . json_encode($checkResult) . '执行时间:' . $total . "秒");
193 197 $activeResult = false;
194   - if ($checkResult) {
  198 + if (isset($checkResult["status"])) {
195 199 //success:激活成功 fail:激活失败,无效标签 activated:已激活过
196 200 if (isset($checkResult["status"]) && "success" == $checkResult["status"]) {
197 201 // 记录扫码次数
... ... @@ -398,15 +402,33 @@ class DefaultController extends BaseController
398 402 $e->message = '缺少必要参数!';
399 403 return $this->renderJson($e);
400 404 }
401   - // 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活
402   - $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
403   - if (empty($hasRecord)) {
404   - $e->success = 0;
405   - $e->message = '暂无激活!';
406   - return $this->renderJson($e);
  405 + // 校验UUID是否有效 2 无效 0 有效未激活 1 有效已激活 (//result 校验UUID是否有效 -2 无效 0 有效未激活 2 有效已激活)
  406 + $startTime = microtime(true);
  407 + $result = CheckActiveHelper::getAppCheck($uuid, "");
  408 + $etime=microtime(true);//获取程序执行结束的时间
  409 + $total=$etime-$startTime; //计算差值
  410 + Log::DEBUG("扫码调用检查接口结果:" . json_encode($result) . '执行时间:' . $total . "秒");
  411 + if (isset($result["code"])) {
  412 + if ($result["code"] == 2) {
  413 + $e->success = 1;
  414 + $e->message = '已激活';
  415 + } else if ($result["code"] == 0) {
  416 + $hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
  417 + if (empty($hasRecord)) {
  418 + $e->success = 0;
  419 + $e->message = '暂无激活!';
  420 + return $this->renderJson($e);
  421 + } else {
  422 + $e->success = 1;
  423 + $e->message = '已激活';
  424 + }
  425 + } else {
  426 + $e->success = 2;
  427 + $e->message = '该二维码无效!';
  428 + }
407 429 } else {
408   - $e->success = 1;
409   - $e->message = '已激活';
  430 + $e->success = 2;
  431 + $e->message = '该二维码无效!';
410 432 }
411 433 return $this->renderJson($e);
412 434  
... ...
app-wx/web/dist/js/check-app.js
1   -define("check-app",["mk7/app"],function(n){var t=Dom7,e=function(){var n=t(".ui-loading-block");0==n.length&&(t(".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"),t=document.createElement("p");t.className="notice",n&&(t.innerHTML='加载速度太慢?试试<a class="link" href="#" onclick="javascript:location.reload();return false;">重新加载</a>',n.appendChild(t))},window.waitingTime))},o=!0;return n.name="check",n.routes={index:function(){return o=!1,e(),n.runController("index")},"*":function(){return o=!1,e(),n.runController("index")},"scan-count/:uuid/:scancount":function(t,i){return o=!1,e(),n.runController("scan-count",{uuid:t,scancount:i})},"warning/:uuid":function(t){return o=!1,e(),n.runController("warning",{uuid:t})},"submit/:uuid":function(t){return o=!1,e(),n.runController("submit",{uuid:t})},"error/:uuid":function(t){return o=!1,e(),n.runController("error",{uuid:t})},"success/:uuid":function(t){return o=!1,e(),n.runController("success",{uuid:t})},"info/:uuid/:number_code":function(t,i){return o=!1,e(),n.runController("info",{uuid:t,number_code:i})}},n}),define("check/error-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,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,t,e,o,i){var n=new n,c=Dom7,a=(Template7,1),r=0,s=2,u=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(),c(".scan-button").attr("disabled","disabled"),c(".scan-button").text("正在调起扫码……")},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){if(d.uuid.indexOf("@")==-1)return e.toast({content:"该智能防伪二维码无效"}),!1;var d=d.uuid.split("@"),l=t.to("check#warning/"+d[0]),m=t.to("check#scan-count/"+d[0]+"/"+u);c.ajax({method:"POST",url:t.to("check/default/check-active"),data:{uuid:d[0]},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){u=n.scan_count,m=t.to("check#scan-count/"+d[0]+"/"+u),n.success==a?window.location.href=m:n.success==r?window.location.href=l:n.success==s?e.toast({content:"该智能防伪二维码无效"}):e.toast({content:"该智能防伪二维码无效"})},error:function(n){},complete:function(t){n.hideIndicator()}})}else e.toast({content:"请扫描智能防伪二维码"})}}),setTimeout(function(){c(".scan-button").removeAttr("disabled"),c(".scan-button").text("点击扫描标签")},1e3)})},n}),define("check/info-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7;Template7;return i.config({debug:!1,appId:window.$site.appid,timestamp:window.$site.timestamp,nonceStr:window.$site.noncestr,signature:window.$site.signature,jsApiList:["previewImage"]}),n.run=function(){var n=this;n.setPageTitle("隐私信息"),n.loadData(n.params.uuid,n.params.number_code),n.popstate()},n.bindEvents=function(){c(".back-button").click(function(){window.history.go(-1)}),c(".image_button").click(function(){var n=c(this).attr("data-url");return e.isEmpty(n)?(e.toast({content:"该图片不存在",closeDelay:3e3}),!1):(c(".scan-image-div").html('<img src="'+n+'" class="scan-image"/>'),void c(".scan-image").click(function(){var n=[],t=c("#info").find(".image_button");c.each(t,function(t,e){var o=c(e).attr("data-url");n.push(o)});var e=c(this).attr("src");i.previewImage({current:e,urls:n})}))}),c(".scan-image").click(function(){var n=[],t=c("#info").find(".image_button");c.each(t,function(t,e){var o=c(e).attr("data-url");n.push(o)});var e=c(this).attr("src");i.previewImage({current:e,urls:n})}),c(".vedio_button").click(function(){var n=c(this).attr("data-url");if(e.isEmpty(n))return e.toast({content:"该视频不存在",closeDelay:3e3}),!1;var t="<video class='scan-image' style='border: 1px solid #cce1f1;object-fit: fill;height:15rem;' alt='商品视频' ";t+="controls='controls'> <source src='"+n+"' type='video/mp4'>您的浏览器不支持 video 标签。</video>",c(".scan-image-div").html(t)})},n.loadData=function(n,o){var i=this;c.ajax({method:"POST",url:t.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):e.toast({content:n.message,closeDelay:3e3})}catch(t){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.toast({content:"提交出错,请联系系统管理员"})},complete:function(n){i.hideIndicator()}})},n.popstate=function(){window.addEventListener("popstate",function(n){window.location.href=t.to("check#index")},!1)},n}),define("check/scan-count-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7,a=(Template7,0),r="";return n.run=function(){var n=this;a=parseInt(n.params.scancount),r=n.params.uuid,n.setPageTitle("验证标签"),n.render(),c(".count-num").html(a)},n.bindEvents=function(){c(".scan-button").click(function(){""!=r&&void 0!=r?window.location.href=t.to("check#submit/"+r):window.location.href=t.to("check#index")})},n}),define("check/submit-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7,a=(Template7,"");return n.run=function(){var n=this;a=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 e.isEmpty(o)?(e.toast({content:"请拍照文件上传后再试!"}),!1):void c.ajax({method:"POST",url:t.to("check/default/check-actived"),data:{upload_file:o,uuid:a},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=t.to("check#success/"+a):window.location.href=t.to("check#error/"+a)}catch(o){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.toast({content:"提交出错,请联系系统管理员"})},complete:function(t){n.hideIndicator()}})})},n.uploadImg=function(n){var t=this;i.ready(function(){i.chooseImage({count:1,sizeType:["compressed"],sourceType:["album","camera"],success:function(e){e.localIds.length>0&&t.upload(e.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:t.to("check/default/update-serviceid"),data:{service_id:n.serverId,uuid:a},dataType:"json",beforeSend:function(){r.showIndicator()},success:function(n){try{if(n.success){var t=n.img_path;o.attr("data",t),o.attr("src",n.show_path)}else e.toast({content:n.message,closeDelay:3e3})}catch(i){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.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,t,e,o,i){var n=new n,c=Dom7,a=(Template7,"");return n.run=function(){var n=this;a=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 e.isEmpty(o)?(e.toast({content:"请填写提取码"}),c(".input-num").focus(),!1):e.isEmpty(a)?(e.toast({content:"缺少必要参数请退出重试"}),!1):void c.ajax({method:"POST",url:t.to("check/default/get-info"),data:{uuid:a,number_code:o},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=t.to("check#info/"+a+"/"+o):e.toast({content:n.message,closeDelay:3e3})}catch(i){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.toast({content:"提交出错,请联系系统管理员"})},complete:function(t){n.hideIndicator()}})})},n}),define("check/warning-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7,a=(Template7,"");return n.run=function(){var n=this;a=n.params.uuid,n.setPageTitle("验证标签"),n.render()},n.bindEvents=function(){c(".scan-jump-button").click(function(){""!=a&&void 0!=a?window.location.href=t.to("smart#enter/"+a):window.location.href=t.to("check#index")})},n});
2 1 \ No newline at end of file
  2 +define("check-app",["mk7/app"],function(n){var t=Dom7,e=function(){var n=t(".ui-loading-block");0==n.length&&(t(".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"),t=document.createElement("p");t.className="notice",n&&(t.innerHTML='加载速度太慢?试试<a class="link" href="#" onclick="javascript:location.reload();return false;">重新加载</a>',n.appendChild(t))},window.waitingTime))},o=!0;return n.name="check",n.routes={index:function(){return o=!1,e(),n.runController("index")},"*":function(){return o=!1,e(),n.runController("index")},"scan-count/:uuid/:scancount":function(t,i){return o=!1,e(),n.runController("scan-count",{uuid:t,scancount:i})},"warning/:uuid":function(t){return o=!1,e(),n.runController("warning",{uuid:t})},"submit/:uuid":function(t){return o=!1,e(),n.runController("submit",{uuid:t})},"error/:uuid":function(t){return o=!1,e(),n.runController("error",{uuid:t})},"success/:uuid":function(t){return o=!1,e(),n.runController("success",{uuid:t})},"info/:uuid/:number_code":function(t,i){return o=!1,e(),n.runController("info",{uuid:t,number_code:i})}},n}),define("check/error-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,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,t,e,o,i){var n=new n,c=Dom7,a=(Template7,1),r=0,s=2,u=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(),c(".scan-button").attr("disabled","disabled"),c(".scan-button").text("正在调起扫码……")},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){if(d.uuid.indexOf("@")==-1)return e.toast({content:"该智能防伪二维码无效"}),!1;var d=d.uuid.split("@"),l=t.to("check#warning/"+d[0]),m=t.to("check#scan-count/"+d[0]+"/"+u);c.ajax({method:"POST",url:t.to("check/default/check-active"),data:{uuid:d[0]},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){u=n.scan_count,m=t.to("check#scan-count/"+d[0]+"/"+u),n.success==a?window.location.href=m:n.success==r?window.location.href=l:n.success==s?e.toast({content:"该智能防伪二维码无效"}):e.toast({content:"该智能防伪二维码无效"})},error:function(n){},complete:function(t){n.hideIndicator()}})}else e.toast({content:"请扫描智能防伪二维码"})}}),setTimeout(function(){c(".scan-button").removeAttr("disabled"),c(".scan-button").text("点击扫描标签")},1e3)})},n}),define("check/info-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7;Template7;return i.config({debug:!1,appId:window.$site.appid,timestamp:window.$site.timestamp,nonceStr:window.$site.noncestr,signature:window.$site.signature,jsApiList:["previewImage"]}),n.run=function(){var n=this;n.setPageTitle("隐私信息"),n.loadData(n.params.uuid,n.params.number_code),n.popstate()},n.bindEvents=function(){c(".back-button").click(function(){window.history.go(-1)}),c(".image_button").click(function(){var n=c(this).attr("data-url");return e.isEmpty(n)?(e.toast({content:"该图片不存在",closeDelay:3e3}),!1):(c(".scan-image-div").html('<img src="'+n+'" class="scan-image"/>'),void c(".scan-image").click(function(){var n=[],t=c("#info").find(".image_button");c.each(t,function(t,e){var o=c(e).attr("data-url");n.push(o)});var e=c(this).attr("src");i.previewImage({current:e,urls:n})}))}),c(".scan-image").click(function(){var n=[],t=c("#info").find(".image_button");c.each(t,function(t,e){var o=c(e).attr("data-url");n.push(o)});var e=c(this).attr("src");i.previewImage({current:e,urls:n})}),c(".vedio_button").click(function(){var n=c(this).attr("data-url");if(e.isEmpty(n))return e.toast({content:"该视频不存在",closeDelay:3e3}),!1;var t="<video class='scan-image' style='border: 1px solid #cce1f1;object-fit: fill;height:15rem;' alt='商品视频' ";t+="controls='controls'> <source src='"+n+"' type='video/mp4'>您的浏览器不支持 video 标签。</video>",c(".scan-image-div").html(t)})},n.loadData=function(n,o){var i=this;c.ajax({method:"POST",url:t.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):e.toast({content:n.message,closeDelay:3e3})}catch(t){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.toast({content:"提交出错,请联系系统管理员"})},complete:function(n){i.hideIndicator()}})},n.popstate=function(){window.addEventListener("popstate",function(n){window.location.href=t.to("check#index")},!1)},n}),define("check/scan-count-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7,a=(Template7,0),r="";return n.run=function(){var n=this;a=parseInt(n.params.scancount),r=n.params.uuid,n.setPageTitle("验证标签"),n.render(),c(".count-num").html(a)},n.bindEvents=function(){c(".scan-button").click(function(){""!=r&&void 0!=r?window.location.href=t.to("check#submit/"+r):window.location.href=t.to("check#index")})},n}),define("check/submit-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7,a=(Template7,"");return n.run=function(){var n=this;a=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 e.isEmpty(o)?(e.toast({content:"请拍照文件上传后再试!"}),!1):void c.ajax({method:"POST",url:t.to("check/default/check-actived"),data:{upload_file:o,uuid:a},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?1==n.code?window.location.href=t.to("check#success/"+a):e.toast({content:n.message,closeDelay:3e3}):window.location.href=t.to("check#error/"+a)}catch(o){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.toast({content:"提交出错,请联系系统管理员"})},complete:function(t){n.hideIndicator()}})})},n.uploadImg=function(n){var t=this;i.ready(function(){i.chooseImage({count:1,sizeType:["compressed"],sourceType:["album","camera"],success:function(e){e.localIds.length>0&&t.upload(e.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:t.to("check/default/update-serviceid"),data:{service_id:n.serverId,uuid:a},dataType:"json",beforeSend:function(){r.showIndicator()},success:function(n){try{if(n.success){var t=n.img_path;o.attr("data",t),o.attr("src",n.show_path)}else e.toast({content:n.message,closeDelay:3e3})}catch(i){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.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,t,e,o,i){var n=new n,c=Dom7,a=(Template7,"");return n.run=function(){var n=this;a=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 e.isEmpty(o)?(e.toast({content:"请填写提取码"}),c(".input-num").focus(),!1):e.isEmpty(a)?(e.toast({content:"缺少必要参数请退出重试"}),!1):void c.ajax({method:"POST",url:t.to("check/default/get-info"),data:{uuid:a,number_code:o},dataType:"json",beforeSend:function(){n.showIndicator()},success:function(n){try{n.success?window.location.href=t.to("check#info/"+a+"/"+o):e.toast({content:n.message,closeDelay:3e3})}catch(i){e.toast({content:"出错",closeDelay:3e3})}},error:function(n){e.toast({content:"提交出错,请联系系统管理员"})},complete:function(t){n.hideIndicator()}})})},n}),define("check/warning-controller",["mk7/controller","mk7/url","mk7/utils","mk7/modals","mk7/jweixin"],function(n,t,e,o,i){var n=new n,c=Dom7,a=(Template7,"");return n.run=function(){var n=this;a=n.params.uuid,n.setPageTitle("验证标签"),n.render()},n.bindEvents=function(){c(".scan-jump-button").click(function(){""!=a&&void 0!=a?window.location.href=t.to("smart#enter/"+a):window.location.href=t.to("check#index")})},n});
3 3 \ No newline at end of file
... ...
app-wx/web/src/js/check/submit-controller.js
... ... @@ -53,7 +53,11 @@ define(
53 53 success : function(res){
54 54 try {
55 55 if(res.success) {
56   - window.location.href = url.to('check#success/' + uuid);
  56 + if (res.code == 1) {
  57 + window.location.href = url.to('check#success/' + uuid);
  58 + } else {
  59 + utils.toast({content: res.message, closeDelay:3000});
  60 + }
57 61 } else {
58 62 window.location.href = url.to('check#error/' + uuid);
59 63 }
... ...
common/helpers/CheckActiveHelper.php
... ... @@ -17,7 +17,7 @@ use function base64_encode;
17 17  
18 18 class CheckActiveHelper
19 19 {
20   - const CHECK_URL = 'http://check1.bosch-smartlife.com/app_qrv';
  20 + const CHECK_URL = 'http://check1.bosch-smartlife.com/qrv_zhoundlee';
21 21  
22 22 const ACTIVE_URL = 'http://check1.bosch-smartlife.com/app_activate';
23 23  
... ... @@ -39,16 +39,33 @@ class CheckActiveHelper
39 39 try {
40 40 $curl = curl_init();
41 41 curl_setopt($curl, CURLOPT_URL, self::CHECK_URL);
42   -
43 42 // 获取图片内容
44 43 $fp = file_get_contents($imageFullPath); // 获取图片的二进制数据
45   - $image = base64_encode($fp); //图片二进制数据base64编码
  44 + $filename_root = $_SERVER['DOCUMENT_ROOT'];
  45 + $path = $filename_root. '/tmp';
  46 + if (!is_dir($path)) {
  47 + @mkdir($path, 0777);
  48 + }
  49 + $saveFilePath = $path.'/'.$fileName;
  50 + file_put_contents($saveFilePath,$fp);
46 51 // 设置post数据
47 52 $post_data = array(
48   - "img" => $image,
49   - "fileName" => $fileName,
50   - "token" => $token
  53 + 'fileName' => $fileName,
  54 + 'token' => $token
51 55 );
  56 + //$image = "data:image/png;base64," . base64_encode($fp); //图片二进制数据base64编码
  57 + if (class_exists('\CURLFile')) {
  58 + curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
  59 + $post_data['img'] = new \CURLFile(realpath($saveFilePath), '', $fileName);//>=5.5
  60 + } else {
  61 + if (defined('CURLOPT_SAFE_UPLOAD')) {
  62 + curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
  63 + }
  64 + $post_data['img'] = '@' . realpath($saveFilePath);//<=5.5
  65 + }
  66 + ob_clean();
  67 + flush();
  68 + curl_setopt($curl, CURLOPT_HEADER, 0);
52 69 // 如果是https协议
53 70 if (stripos(self::CHECK_URL, "https://") !== FALSE) {
54 71 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
... ... @@ -58,7 +75,7 @@ class CheckActiveHelper
58 75 }
59 76 // 通过POST方式提交
60 77 curl_setopt($curl, CURLOPT_POST, true);
61   - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
  78 + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
62 79  
63 80 // 超时时间
64 81 curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
... ... @@ -76,6 +93,7 @@ class CheckActiveHelper
76 93 //返回内容JSON_DECODE
77 94 return json_decode($callbcak, true);
78 95 } catch (Exception $e) {
  96 + Log::DEBUG("检查图片出错:" . $e->getTraceAsString());
79 97 return false;
80 98 }
81 99 }
... ... @@ -179,4 +197,18 @@ class CheckActiveHelper
179 197 return false;
180 198 }
181 199 }
  200 +
  201 + /**
  202 + * 将图片转成二进制流
  203 + * @param $strTmpName
  204 + * @return string
  205 + */
  206 + private static function base64EncodeImage($strTmpName)
  207 + {
  208 + $base64Image = '';
  209 + $imageInfo = getimagesize($strTmpName);
  210 + $imageData = fread(fopen($strTmpName , 'r'), filesize($strTmpName));
  211 + $base64Image = 'data:' . $imageInfo['mime'] . ';base64,' . chunk_split(base64_encode($imageData));
  212 + return $base64Image;
  213 + }
182 214 }
183 215 \ No newline at end of file
... ...