管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
* @7 L. I- c2 i* W- Q1.添加商品信息
* N* @! y, ]4 y; _, O, @1 r/ E2.添加图片
9 v, v9 }1 \ g3.查询所有产品
+ Y0 g" m" Z- Y; {4.查询某个具体产品信息) B( V |! N9 T7 {
5.删除某个产品+ G! R8 k8 ?0 |
6.删除图片' l6 Q$ I9 ?, w- ]* D' ^* o
7.图像识别
; X h/ H) @- H# G; o( |4 O! @6 X- t9 q# T
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey" y4 n+ ^3 ]0 y+ O3 `, P
1 [7 t+ u! Z+ t9 R; a
PHP示例:4 r, B* v+ I0 K: C# j4 |
- <!--?php
1 Q) [# O; C0 w( s - // +----------------------------------------------------------------------' _, ` `1 ^) R! I; f0 q, p
- // | JuhePHP [ NO ZUO NO DIE ]
# B. s+ Y2 P- a+ G- n+ C - // +----------------------------------------------------------------------
$ [2 |8 w; X# e+ D+ B% W) Z3 B - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
* f! n* j" T. a7 E) C6 H$ b) { - // +----------------------------------------------------------------------2 A/ n) T1 {; m: d& g: X- V' k8 @
- // | Author: Juhedata <info@juhe.cn-->
& M3 @8 I! g, P - // +----------------------------------------------------------------------' _) H8 H) W, x+ p
-
( l+ e& m8 ~# ?7 ~% w8 d - //----------------------------------( g- x) A( C2 M: A4 Z$ M( P1 L
- // 图像识别调用示例代码 - 聚合数据/ N) g% I8 r) q9 U+ G8 G
- // 在线接口文档:http://www.juhe.cn/docs/117* z" \2 Z9 V5 g3 `
- //----------------------------------
4 V. Z U1 E' o: w" ~# G, a -
- W* @+ m3 @( } c4 L% D - header('Content-type:text/html;charset=utf-8');5 Y1 t+ s' Z( A- T5 n7 A
- " K; Y1 e) ^( d3 V
-
9 ~. j8 V7 d% `/ }* b& T* v. _ - //配置您申请的appkey; r! L5 t8 m" w& ~
- $appkey = "*********************";/ k) s6 |% ^: j& Z
-
$ t+ n$ C! d9 K2 Q- I0 O6 @ - 3 y; {* i, S1 u' C+ e
- . \2 b* ]( N# B; e6 C' Q
- ; Z0 \+ A* U1 z1 E
- //************1.图像上传************
0 f- `' M/ F8 Z8 S3 _ - $url = "http://japi.juhe.cn/image_recognition/upload";
- H, j5 X% X* F8 J0 N% ^ - $params = array(
4 K$ O+ U4 B' Y& M4 Z: I2 s - "file" => "",//上传的单张图片
' J' |4 z0 G0 S - "key" => $appkey,//APP Key' h1 h# N1 Q* ^. r
- "pname" => "",//包名
/ K5 H+ k& f( ` G0 x J: l& U2 I - );
+ \" a' r ^" N) e: L - $paramstring = http_build_query($params);
8 T7 i' e* T8 D$ N& s. u - $content = juhecurl($url,$paramstring,1);
# T, n5 R0 V% Q - $result = json_decode($content,true);+ m: l8 E8 y0 B2 M
- if($result){7 B( Z# w% _ D. s2 w0 Q
- if($result['error_code']=='0'){
3 x$ O" J9 ?9 x7 o3 \& E - print_r($result);. w. X5 b F: x/ U
- }else{
1 b% O/ B0 n' ~" A4 b+ F - echo $result['error_code'].":".$result['reason'];
5 `5 \8 O( G. o* r# Q {" I - }9 ~ l8 [6 N: p1 ^/ G
- }else{1 ?) g' r' m; y- P$ b, D
- echo "请求失败";" e9 L8 U1 O" c& L! p8 \5 b
- }! v$ P3 Z" p1 V) j$ @0 U8 D
- //**************************************************
3 U0 W+ n* Y# o' n; M - + N( o: m8 i# y
- , u- D* [) g. i2 c7 C0 [
- 3 _# X& ^+ y2 K$ t, Y
- ! [4 y! B. W% y! S4 V6 H
- //************2.查寻上传图像信息************# x$ ~, ^- m0 _( P
- $url = "http://japi.juhe.cn/image_recognition/findAll";+ z+ c' K- x, s" L& i% [+ R# Q5 s
- $params = array(
% ^7 ^% f: T% w* U - "key" => $appkey,//APP Key
. }% h) | T% Q2 [$ L) i - );' O8 r4 ?* z0 B8 g
- $paramstring = http_build_query($params);
/ d+ F: x) V- S5 L - $content = juhecurl($url,$paramstring);( S, N9 x# s$ Q2 j" q0 G
- $result = json_decode($content,true);* Z& a) P% E4 z& O
- if($result){
6 J3 Z: A; Z) T5 d, l - if($result['error_code']=='0'){
5 U% P; e0 T3 [; M2 B0 h - print_r($result);
* A) Z- B% K! ], Q7 F- W - }else{4 O4 h4 e8 p& J5 o
- echo $result['error_code'].":".$result['reason'];
7 Z- J) s, a8 j5 w - }# V4 O, ?9 Q- x1 _
- }else{
: }& u2 i9 E; n) [- C4 Y- [% e - echo "请求失败";
6 o7 C ?. u) k2 a ~6 b4 _ - }
: j7 d& m* M' u* ? - //**************************************************
) T/ i- ~7 `5 h) j - , h" T7 n# r3 y9 r" F
- " m+ ^. a4 `7 z- E3 \' @9 s; I
-
* x$ Y9 r# J. N& s; p2 b8 { -
6 D, J5 \: h6 P5 D3 X F% s - //************3.删除图像信息************
! f8 ^2 {7 o- i' [( L& K- s - $url = "http://japi.juhe.cn/image_recognition/delete";2 ~$ S' D1 T+ C$ J2 S: D3 x0 Q
- $params = array(+ S! r( N8 k; V. H
- "key" => $appkey,//APP Key/ d I8 t, n! k9 g
- "imageId" => "",//图片ID& ^3 T: \( N; |: P/ P
- );2 |0 i% i4 q0 e' @" d
- $paramstring = http_build_query($params);# K4 J1 a0 M3 r y3 h/ X
- $content = juhecurl($url,$paramstring);' n* E1 i% z* v" ^" k7 F1 n. T
- $result = json_decode($content,true);2 t c# Q/ q* B, N
- if($result){
/ T8 B) _. z3 g - if($result['error_code']=='0'){
$ K p0 I& o+ r& Z7 {& c - print_r($result);
) [' m; H; `4 R/ `5 B: ~7 l: h - }else{
4 F! ~5 d( e$ h3 _ - echo $result['error_code'].":".$result['reason'];0 l0 f+ L: q& i w- y) T- f, y# ?
- }( e* E, L: q3 J7 y$ K
- }else{4 }/ b7 V2 s: a( Z- r4 V
- echo "请求失败";
0 V6 ~ P$ Z0 {1 O5 Q - }1 |' m. e/ U- B$ F. F8 X
- //**************************************************
) Z( w2 d8 A5 c' d - $ }, E# R2 s7 e7 U
- % O8 d5 N. \ C
- 9 D( f0 K1 O! h
- 1 t1 [5 V& }9 x
- //************4.图像识别************
$ y$ o1 J& w7 V% d6 H( X4 g - $url = "http://japi.juhe.cn/image_recognition/check";
( M- |" a3 `% u, I - $params = array(
& J5 \7 W' n6 c0 j, r, y5 w - "file" => "",//上传的图片
0 J! [1 V/ L* V6 B0 H - "key" => $appkey,//APP Key
. V* F& t0 _# A0 s9 H - "pname" => "",//包名
& y$ v- z2 `* u# @, c$ _ - "device_name" => "",//设备名称(如android OS或iphone OS)
3 m o- f/ O% r- C+ Y0 V U - "device_version" => "",//设备版本(如:4.0.3)8 l+ d8 A( h1 M, A5 l: \" v8 x2 }+ n) T
- "latitude" => "",//纬度& @) Y# } B5 Z; V: N, H- f
- "longitude" => "",//经度7 R+ H, @+ b& }( `* t
- "uuid" => "",//设备id' V) q& V; ^7 ~$ \0 X
- "zone" => "",//请求地区
5 u$ f% Z1 J9 p+ m% u3 l: t, M - );
9 _# g/ G: H! s, m7 q, k9 r - $paramstring = http_build_query($params);
6 [. Z8 y* s0 \ - $content = juhecurl($url,$paramstring,1);2 Q1 ]' |3 E+ H
- $result = json_decode($content,true);( j/ J8 v: ^ e9 f1 W% i
- if($result){& I7 {- P* U' y- u4 o" Z
- if($result['error_code']=='0'){ [: G& `- q; y" z$ c
- print_r($result);3 H! x! n4 ~0 c# N: P
- }else{" M$ z& P+ O3 H
- echo $result['error_code'].":".$result['reason'];
0 J. a5 T( I- h5 x! K - }
% L; p) i* A: A; P0 o7 f [ - }else{- v( P& Y: k/ o5 }$ w3 L- l a
- echo "请求失败";* c/ y* L U' R7 w
- }
% Y3 }! |; q: I: y( Q - //**************************************************
& C$ a, a4 u; [; u8 p' {2 {+ L -
J0 E7 ~6 Z# ]$ C# ^8 Y! l3 {# a8 N( C - " X- h- {6 I2 s
- , Z6 H! U! |$ w% e! d8 O
- ( P" M% C3 M1 M( Z( N* X
- , e: M2 J! A0 ~. N
- /**
: P' L/ V* J# T5 W) c - * 请求接口返回内容
; F% o! s- d5 n) q% Y5 F4 u) { - * @param string $url [请求的URL地址]9 a2 T, x( b. h7 z' Y/ W& n
- * @param string $params [请求的参数]( C/ f7 z/ ^1 O8 b
- * @param int $ipost [是否采用POST形式] `% ^" ]& L9 z) \
- * @return string: M t5 E4 k& W) b/ K
- */, W) \" z k _# D5 J5 k9 C, I
- function juhecurl($url,$params=false,$ispost=0){5 I' k: u1 p. Q8 i. [1 `
- $httpInfo = array();/ {: b* ~1 Q, N0 Z
- $ch = curl_init();4 w2 d6 ?/ p1 c, ~, r3 K$ t
- $ {3 v- r; Z" |3 n1 z
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
( Q) i+ g. s8 c7 b. q& ^+ G6 w - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
0 O; c% L8 w$ l1 ~9 Z2 j - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );; i. `4 \' V ]- Z% v4 a
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);: ^& D/ @# @1 R2 i v' o7 s
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
) O& _5 P/ }) z2 R: V8 ^; z - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
* f1 P$ m; [, g, I; w - if( $ispost )
' D) X$ H2 i+ r3 D: X8 S - {9 Y1 @# o- t' v" y
- curl_setopt( $ch , CURLOPT_POST , true );& y0 {% l, g( T( X8 K) k/ e& o
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );4 ~5 Q$ K4 T# c
- curl_setopt( $ch , CURLOPT_URL , $url );, n$ I3 M/ H9 Y9 t
- }4 d9 `6 v+ c+ K( B% S: M
- else
* \1 T$ ~; E0 y. O. f; C4 z" k - {; M9 m) `! s9 {
- if($params){6 v" k0 T- m; d+ A' j6 f% ]
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );; B7 {) H+ }1 }- [
- }else{
+ l; B' c- a+ v - curl_setopt( $ch , CURLOPT_URL , $url);
" l& R6 G9 O7 q4 c/ l1 ~6 c [; K - }
% v. V J; z. a - }
4 f5 Q3 Z- u0 x - $response = curl_exec( $ch );
' |4 W C5 Q7 H, G& W6 k2 m - if ($response === FALSE) {8 t- F2 L! e. a* q, d9 ?/ @
- //echo "cURL Error: " . curl_error($ch);
$ g7 A L8 u4 H( w. ^8 |) W U6 L - return false;* j3 R: J* \, G' E# v
- }
- \3 h# U% u, ~: W2 C- c) I - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$ V5 @- W9 n2 D, o3 ]* H$ } - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );. P. ~6 D' B' ~ d; c9 M6 ?
- curl_close( $ch );
% R3 M' ^0 d! ]( p! X. T0 p6 o - return $response;3 S( x; [8 c& L$ e5 | C
- }
复制代码
' Y$ c$ B+ c5 D @# K3 ^. H: I6 U' o9 u3 @" a( s: F9 _) g
|
|