管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。) g2 O& Z& B! t& x3 U' s
1.添加商品信息
8 j: {7 h4 L0 n# j/ J8 n2.添加图片6 R+ m& s: x' p, m. }) s, c' ?( u
3.查询所有产品$ f* q6 |5 i# T- r
4.查询某个具体产品信息
4 x8 l k8 S0 h+ d5.删除某个产品5 `" E) Q/ z+ b+ _
6.删除图片
; Z0 Q4 L z: H/ ~/ L: B% D/ C- {- }7.图像识别5 Y' N5 a+ m; W6 W- X
1 }/ G# D! U0 ]+ S- y% W d, m
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey* U2 I4 L) o- k F" N/ E7 C( |: x) P
+ q6 k" t. I% O! y/ e" U" e7 k
PHP示例:
8 d6 H% s' H9 T4 m% x" p- <!--?php
6 c" Z% [3 i% p, v( F3 `% i - // +----------------------------------------------------------------------: O: a" @( b8 w/ s! h
- // | JuhePHP [ NO ZUO NO DIE ]
' }& E4 Y0 O- X - // +----------------------------------------------------------------------
. ]$ j. @# G- `& f! i$ ~ - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.% b# f; A( E) a$ W7 I
- // +----------------------------------------------------------------------
$ }1 g; y* x ^+ j/ x) X: m; o2 T - // | Author: Juhedata <info@juhe.cn--># n+ E# X6 o3 Q- O
- // +----------------------------------------------------------------------
+ y% m0 q( \" V" q - ; i% I% _6 b+ d
- //----------------------------------
$ q( ~, U3 y/ X- g - // 图像识别调用示例代码 - 聚合数据
; p: w- o. U7 p* }: t - // 在线接口文档:http://www.juhe.cn/docs/117
: g' _" Y1 w6 Y, x! G { - //----------------------------------4 a, E* i& v9 e( @" Z
- 2 q% ` o/ w3 e! t3 S
- header('Content-type:text/html;charset=utf-8');
* B7 J3 S% t( I n. s' U - 6 S7 f. G0 m3 H. g. B) F9 B# O
- F, e8 R) U) p, s- ~
- //配置您申请的appkey0 `3 ]6 u1 O! |$ ~; I1 v
- $appkey = "*********************";. ~4 k! v7 _) p" Q
- 0 A# |2 y% K$ r- l
- k. Y z& x# x/ @" N1 Y, @
-
8 ?2 f4 p3 p$ u+ R t -
}4 L# X) Y8 t& s' X7 w - //************1.图像上传************
5 u& ^+ {7 S7 g: L+ `+ ]( H - $url = "http://japi.juhe.cn/image_recognition/upload";
* h9 P6 ]8 V9 {0 ~- P/ D - $params = array(
3 d6 V- ~- V5 m2 }; n# d5 H# e - "file" => "",//上传的单张图片, ~, [9 K* p! d' t0 @. I
- "key" => $appkey,//APP Key' f) U( R( C& ~
- "pname" => "",//包名
, A6 j- }- z; }0 c# m$ g - );- ^/ R1 T% t" [/ u6 U3 Q, \. H
- $paramstring = http_build_query($params);6 |. s% h) r8 F- ^; M
- $content = juhecurl($url,$paramstring,1);& a7 R! d2 a, f$ m
- $result = json_decode($content,true);
7 q" G/ x, K$ q3 J3 Z# V+ | - if($result){1 M3 R3 \% e1 t M
- if($result['error_code']=='0'){
7 ~* k: Z1 C" j! `/ _; l% N - print_r($result);( x3 }7 a6 m# [) H7 U: A
- }else{7 y1 A) |# c8 I8 [& y8 z2 X
- echo $result['error_code'].":".$result['reason'];* @. F& O* W1 ?: k/ y& Z6 D7 f, _+ R, m
- }
% y9 \/ z* b$ Z% l/ F* Y. ^- j - }else{& m% B# o2 e! B+ j
- echo "请求失败";
2 L1 ]6 ~4 d4 b( U3 J+ v: c; W/ c - }
* {- @8 u' F. ` - //**************************************************2 Y; H# r$ U9 x" }( `9 ` D" x: R
-
" t0 Z, ^6 L3 H( L - 4 y: x6 T+ D2 b
-
2 d3 q. \3 k, p8 F9 Q' D5 w1 r% a -
9 a1 R- d: c5 x" I: I - //************2.查寻上传图像信息************
3 x" Z; S4 v) D+ l - $url = "http://japi.juhe.cn/image_recognition/findAll";7 V9 l& B& |- u. W( \
- $params = array($ R" ~2 c; X* Y" X8 h1 G" p% `
- "key" => $appkey,//APP Key
8 i/ h: W5 F, \" l+ ]/ u. `# }- N - );
" b- y9 K# Q! q - $paramstring = http_build_query($params);( n+ K, c% J8 g# f, ~6 v% b3 @
- $content = juhecurl($url,$paramstring);
" N! }; n, E- F' X# p% s l - $result = json_decode($content,true);
; `! `& L/ U/ V! J+ N& E/ [+ m2 Z5 ] - if($result){+ c# |/ p. |4 E
- if($result['error_code']=='0'){
0 i" _5 e6 p2 m - print_r($result);& ]* C* n6 E% z* T
- }else{$ `) p/ h7 ?) y* k( ~% }" w( Q! ^
- echo $result['error_code'].":".$result['reason'];
0 z; l: w! l$ G, a3 Y - }
! l3 x' `+ k5 P1 h" b2 g0 I - }else{
7 H. J+ O. |. b# z/ X3 v - echo "请求失败";
2 R3 X; i" s2 z: r - }; z% a; G. F+ C: k/ ^2 ^
- //**************************************************
+ l E C2 K7 J1 u - 9 e/ u! y& ]2 B- u8 r& ^
- 7 g# i) x% ^% A
-
- g; u8 T& p5 Y9 x3 j -
2 x6 Z J9 K* \' V+ A& L; F - //************3.删除图像信息************2 k- s' t) q- F2 s
- $url = "http://japi.juhe.cn/image_recognition/delete";
8 c$ G8 Z5 J5 K. N1 a1 s) k - $params = array(4 c5 Y6 L& w W- T
- "key" => $appkey,//APP Key. x Q' L+ p8 [( ? ?* F( o
- "imageId" => "",//图片ID
: U- K6 I [$ k* n$ q Y$ W - );1 e" w, p r, a; l5 G" D
- $paramstring = http_build_query($params); t5 |+ Q$ D) b; k7 [& G* o" W* s
- $content = juhecurl($url,$paramstring);; p3 y U& p$ ~7 j
- $result = json_decode($content,true);
* u0 R7 f9 s) f/ r+ T, }! K - if($result){# [; } I3 S8 g) c+ L% I* j' c
- if($result['error_code']=='0'){
( r0 \0 D9 ?, b- ]# I - print_r($result);7 z8 c/ g0 D( n
- }else{
- t- g+ f: o4 [- t' E - echo $result['error_code'].":".$result['reason'];
. u$ s# n; j* Y1 ~ - }9 f) S2 C, y W2 m
- }else{ n, S3 `9 Q0 C2 _ p
- echo "请求失败";
- \( N7 i5 ?6 ]( Z, Z% u - }
( A" ?7 O U" T- \4 Y" A; p - //**************************************************# F% w/ u, W% e9 f$ V. X
- 3 C- @* P: N( \1 {. Z( Y4 B
-
" F5 R4 O6 I! p -
: v3 q5 O: t7 j/ r4 x' M! Q -
1 }0 B* B4 t0 J9 x# V! F - //************4.图像识别************! z2 ^8 L# ^+ U3 K5 C# F
- $url = "http://japi.juhe.cn/image_recognition/check";3 U2 A1 U4 e' L. h: h; \3 G- m
- $params = array(5 W9 y. a3 B# p( `" ^% e" `
- "file" => "",//上传的图片2 d+ v i4 W* o/ R7 j) b
- "key" => $appkey,//APP Key! m5 S6 ]/ M$ ?9 E: Q
- "pname" => "",//包名* y# U5 p- d: v# o e
- "device_name" => "",//设备名称(如android OS或iphone OS)' N6 D" _+ C' O+ e
- "device_version" => "",//设备版本(如:4.0.3)
+ {2 t) D& [1 U+ g4 f5 p - "latitude" => "",//纬度0 D5 v9 N+ f( Y, k
- "longitude" => "",//经度( C0 a$ C, j- h0 e8 b" @
- "uuid" => "",//设备id7 o5 x8 A; \: p( C
- "zone" => "",//请求地区
+ i' J7 r: G Z. h9 H! L5 f - );9 ~5 _3 R, g4 k9 y
- $paramstring = http_build_query($params);
9 Y) |# a9 _& H. v - $content = juhecurl($url,$paramstring,1);/ g' A6 A# l0 \* [+ W
- $result = json_decode($content,true);
7 G6 b% ?( q9 y8 o5 b( l - if($result){8 N9 H- `0 w. j% h; G
- if($result['error_code']=='0'){
0 E9 w9 r4 v! |) U0 s& H! a - print_r($result);
: [1 e( F' Z. }( L/ c5 o$ e - }else{ V0 F3 u d7 G- `4 I$ o
- echo $result['error_code'].":".$result['reason'];
* F& H$ X" w9 {$ S& Q - }) _' ?2 z1 P7 w0 ~* `0 j
- }else{3 Y8 l$ O" W, a& a' ?* f
- echo "请求失败";- K5 }# L% @9 C- \/ E
- }! B7 B7 E: R5 ~. r$ ]9 o" [* j
- //**************************************************
9 @, b* {' C, w. `6 a# @ - 3 |% r6 H( W: R" J
- 9 f! \2 x* E6 V7 t
-
' q% ?/ G- C+ X* i -
, B4 J' d" u! P" W, w, D -
- E) ], A P; G! j0 e0 G/ t, q - /**8 Y2 |3 Q* J" V+ b& t
- * 请求接口返回内容
. ^9 P- w% `+ o0 x - * @param string $url [请求的URL地址]
4 L r8 F6 o9 p7 @/ b - * @param string $params [请求的参数]
, J0 W% [/ R2 K# k1 k8 m - * @param int $ipost [是否采用POST形式]& X1 o2 L1 I4 E
- * @return string
- z. p, m# u+ H1 h# V6 n6 S - */
: E7 L/ h8 U( O0 N - function juhecurl($url,$params=false,$ispost=0){0 d0 Q* ]- k' q: k5 C
- $httpInfo = array();0 l6 t3 B" Q- b
- $ch = curl_init();3 p3 {" t" Z6 P) m: {
-
. v$ j2 c1 S ~" p0 U, Y j - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
) O, q- o+ g' w# t1 W - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
C4 ]- o; u' n6 z( o8 a - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
7 _, B% B& @( l) N' q - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);% ?2 x8 ?+ t, e3 O
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );& `5 h' a. v- ?8 s+ \; \% E+ Q
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);6 I/ B6 I( j2 r" {
- if( $ispost )
1 y' x7 w! R! B5 b- o% P) u - {: ]7 v$ n/ W. ?0 h0 f0 S& ?2 D
- curl_setopt( $ch , CURLOPT_POST , true );& K2 {' F( ?9 q3 u0 I1 {8 {
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
1 Y9 ]; d" y7 \: `2 `4 P8 c - curl_setopt( $ch , CURLOPT_URL , $url );
9 }& S0 o1 D0 M) i* n" ? - }
% x6 P* l' h0 x - else
L4 Y/ S0 ?! K( J+ P" k - {
' h) b7 ?5 K! M, A" ~ - if($params){$ E3 l$ A. {( E% ]
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );1 n' b+ H) L5 c0 N+ {
- }else{3 l" z- _' f* h: B/ r1 w) }
- curl_setopt( $ch , CURLOPT_URL , $url);% F, p" O; g: Q3 n- A: g8 w/ O' ~
- }, c/ B( ~3 C" U+ l) }
- }3 [" a/ L, ]: ^. U1 U9 i
- $response = curl_exec( $ch );7 |+ d/ O/ L$ |& s3 g
- if ($response === FALSE) {) v4 i# f0 i4 S6 x+ W" l
- //echo "cURL Error: " . curl_error($ch);" l, `0 R$ Z. |# f# s: Z6 P+ G
- return false;+ d5 `* `- ~8 A, P) u3 m
- }; ~/ h% A f7 l6 ?( y
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
3 Y& ]5 C4 V' m& N - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
2 S& P5 H& r& }4 P2 ]7 r - curl_close( $ch );" j% D2 @! A: }3 h7 t$ Q' {5 h
- return $response;! A2 m! O+ c/ b
- }
复制代码
; J: p: r6 ~1 o+ P0 S6 u3 D1 U# Y
g' P- ], U- \* [ |
|