管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。/ i5 W9 ?; M: {0 {8 r1 W+ |
1.添加商品信息
2 y# K& n' ^2 b# a0 P: H) m2.添加图片
" U7 C( P* b4 C) k# N; a3.查询所有产品
% l6 G, p- d4 _9 Z0 s" S4.查询某个具体产品信息
2 [& }0 F, P: r1 D% x7 H5.删除某个产品
6 D# ]2 Q. A, P1 x, H3 R3 M4 J6.删除图片
9 P5 S" g3 K9 V5 |7.图像识别1 V+ [8 T# n# d7 @4 g
& H1 A$ \ }: A# a- K) U图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey; K4 H4 |- V0 q1 O8 f
" E* ]4 `, D; LPHP示例:
3 E3 `7 i/ V. e4 a7 q, ~( e) v- <!--?php
) R/ r" S$ V1 X7 [5 X$ q - // +----------------------------------------------------------------------
# I% f1 |7 _6 W% E& N' { - // | JuhePHP [ NO ZUO NO DIE ]" \; w6 t2 J. D c) `7 c
- // +----------------------------------------------------------------------
( j' [% H' D. Q# t3 w; d) V3 E, f - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
$ h& l! ?% i4 a8 n# o: U" g - // +----------------------------------------------------------------------
0 C8 ^ B! ^ j' q- J - // | Author: Juhedata <info@juhe.cn-->
0 |5 `% [; d& z0 a - // +----------------------------------------------------------------------6 B, |1 D) r l
- * `* L3 |6 _8 x+ `
- //----------------------------------
- |) G7 j/ _6 n9 V7 J9 T - // 图像识别调用示例代码 - 聚合数据
$ C J& Y& |) i1 g5 O% u W* }6 @ - // 在线接口文档:http://www.juhe.cn/docs/117- G( R7 H9 c6 O" N
- //----------------------------------; M- M/ C, r& M$ H8 g/ h7 Y
-
8 P0 W% j0 U$ x3 F( i5 H/ G! G - header('Content-type:text/html;charset=utf-8');! K8 @, O$ H) E4 C3 c, T" W& m
-
6 s9 U" P: P2 g9 R. j - : w& D5 Y( D% t4 s
- //配置您申请的appkey
C5 F0 a8 r: K - $appkey = "*********************";
' A* {& j2 f+ j# ^6 n/ P+ n - ( Z* d# h! O3 i. v0 [
- ) }1 e4 F0 s) ^% z
- 1 L& j; P9 ?0 m6 w( v
- % F! u4 x6 H- \/ [# V2 f% l/ [- u! a
- //************1.图像上传************
( O/ C9 k: [: K" j5 A6 \' x4 p - $url = "http://japi.juhe.cn/image_recognition/upload";
& A# J4 o8 Q3 m) M - $params = array(- B# T8 r, O- d. ?
- "file" => "",//上传的单张图片+ T# Q) L1 j8 J2 L7 c) n* w9 G
- "key" => $appkey,//APP Key
, Q' Y' f. J. V0 g& E: h2 p - "pname" => "",//包名- V4 d7 F( }+ M
- );! @( k7 T4 z) n, G7 \8 y
- $paramstring = http_build_query($params);5 I4 w X t! J4 @/ D) C
- $content = juhecurl($url,$paramstring,1);/ K; X# g( n: O
- $result = json_decode($content,true);/ E, P9 o' `- I
- if($result){ L4 d7 i9 Z$ t+ E9 `
- if($result['error_code']=='0'){
: h/ z! }2 `- c: L; H' L% ~7 { - print_r($result);
% b& M' q1 y# Z8 W4 V - }else{9 i/ Y) p5 y& c3 u. G3 V
- echo $result['error_code'].":".$result['reason'];
8 g0 Y7 T8 Y$ ^7 R" U2 A - }
4 [" u! O3 ^' x& ]! I, Q4 p2 d - }else{
3 o5 A4 _- h9 w( A+ D# H. i& r - echo "请求失败";2 J6 q6 [* K+ A
- }6 R& z& W" n3 M6 E2 H6 J& A1 p
- //**************************************************
- J$ y' k# E9 Z5 c# g& O - : ?' p; ^: c9 J3 {3 ?8 Y2 _+ ]1 A/ _! q
-
! G& ]2 V! Q5 W" Y: w% n - , v8 Z9 _+ ]$ }* ^3 K: u1 I( v# @
-
, D; t3 s* Q [9 k* T R4 f6 i - //************2.查寻上传图像信息************
( e2 L# P8 O H# b( p8 u - $url = "http://japi.juhe.cn/image_recognition/findAll";$ g/ \& {# l* o" y( D: D
- $params = array(7 B2 v* f1 l$ t. _. g9 ? t6 y% [
- "key" => $appkey,//APP Key& N x- y2 B# z$ s
- );
" \, X; U# b0 o* z0 \( I0 Y+ ^ - $paramstring = http_build_query($params);
6 e5 P1 E. |) M F* a2 l- M - $content = juhecurl($url,$paramstring);
( x, a1 o M2 O. G - $result = json_decode($content,true);% Z$ a- M2 i' H! u* t1 H# {
- if($result){
7 G1 \/ x$ c) v( L7 T - if($result['error_code']=='0'){7 p5 e) @/ H) _) f+ n, a
- print_r($result);/ I2 N5 _/ g' p. Y1 q6 y2 H3 Y
- }else{
. \4 }9 W9 D; e0 V5 m T$ j - echo $result['error_code'].":".$result['reason'];
- Z; j+ y1 @& H+ [ - }
5 u" `/ Z5 c$ V2 n- R! t9 } - }else{
4 J& s4 E4 ^2 M1 P2 a - echo "请求失败";
( |! k7 P% V: p/ y; ?* C! K$ i - }( Y( r9 c' u$ I" q& _+ m2 g
- //**************************************************
8 n( ?( R* z" o! c8 C b+ z) Q - + U( N4 M q3 Y( ?
- - P) B0 a+ C7 Q8 e
- ( X! o5 E9 Q( t2 p- j# @6 Y! ]% A
- / x8 Y& T! @1 g/ Q# `1 V
- //************3.删除图像信息************
7 h: \% o* W4 I - $url = "http://japi.juhe.cn/image_recognition/delete";
& y* [) I( L( D5 J - $params = array(
2 Q4 r4 |1 ~/ d9 x0 s - "key" => $appkey,//APP Key/ R7 r- D1 h& T3 f8 l6 ~
- "imageId" => "",//图片ID
6 r: b$ p+ x( T% s4 ]7 R - );
8 Q% @ f" f9 l1 W' \" P) v" J6 T - $paramstring = http_build_query($params);# X" w9 p% Q9 }4 V0 ]
- $content = juhecurl($url,$paramstring);% r7 c% n3 H' n7 }/ T
- $result = json_decode($content,true);
0 a. H# L3 _/ r* ^/ m+ N. }$ E - if($result){
" b/ O. K3 a+ d. B% ^, W - if($result['error_code']=='0'){! z& N5 e" L5 r% C
- print_r($result);
7 u& k9 T& S. g) ^4 u# x - }else{# N9 d$ ]! T( v, p; t& a, u% c0 L
- echo $result['error_code'].":".$result['reason'];5 F" u7 Z% y. H1 T8 i" ]5 ?/ [1 _
- }
4 N8 P" y! M" _) @8 v. u# q - }else{
1 w6 s `" @0 V+ A+ g" ^4 t - echo "请求失败";; p2 z4 d$ B& m7 Z9 d
- }
% Z4 H2 s+ |4 o, w9 {: X+ s - //**************************************************
) c4 v- n7 ?; [1 P/ f! I$ u -
- t, v" @! F! o# X u3 i0 g - % f% z: a& B$ M9 @3 L) w1 N. u
- . m/ I: V( a1 I" |% C K5 ~/ f
-
: k7 T, r& Z3 K5 j, E - //************4.图像识别************/ P# \& W8 \; E6 K. z% c3 U4 t* |2 P
- $url = "http://japi.juhe.cn/image_recognition/check";
) W! @2 j# v1 U - $params = array(' H/ @% l D3 g/ v
- "file" => "",//上传的图片- C. |% a( y* b6 d, D$ Q
- "key" => $appkey,//APP Key: P3 K" ?/ g7 z O* K
- "pname" => "",//包名# ^8 {2 S. B3 \1 b* @6 H1 Y
- "device_name" => "",//设备名称(如android OS或iphone OS)7 p' \ S- z- Y
- "device_version" => "",//设备版本(如:4.0.3)2 ~) b$ \/ d" ]! g
- "latitude" => "",//纬度; w8 u8 b7 M. O0 s/ e9 E
- "longitude" => "",//经度! o/ l6 S! Y2 a4 M- J8 u
- "uuid" => "",//设备id
9 i& S6 q2 b' r - "zone" => "",//请求地区+ g; e6 ^$ e5 g
- );
0 }4 h( }( g- U9 z( ~6 g5 k+ v0 ? - $paramstring = http_build_query($params);6 I; q" a# W% l3 {- A- J
- $content = juhecurl($url,$paramstring,1);5 N+ y, B0 e F4 M
- $result = json_decode($content,true);
: I8 W6 m( d; w8 F1 F - if($result){, G8 `" D1 S: U: f& _$ M# E
- if($result['error_code']=='0'){
" U& l: b6 x. m# N; Q, [2 M - print_r($result);
* }/ z8 `* R: ]( W - }else{
; |, J/ [- b; ` - echo $result['error_code'].":".$result['reason'];6 [/ I( [2 Y. z/ @, t& _( M
- }
3 Y( s7 A% J, u/ s: q3 F - }else{7 J/ l% _& n7 {: B- x, g* Y' s8 l' _
- echo "请求失败";, P5 }4 d/ c/ ?; V: _/ t
- }8 ^5 F& |) ~3 X3 t2 }7 q8 q
- //**************************************************+ f/ |8 L6 l- r8 n
- ' ?4 F; a9 R9 s. ^) f' [
-
* m/ Z" O ?/ J% c; r q -
8 i$ K0 R. [; O! ?# v' c - ( H. q' \6 g+ {- g% y
-
1 P1 R) H9 W: H: R - /**/ L. V" q, ^$ Z1 J3 y0 D+ u: g; G. }
- * 请求接口返回内容( q: p" \* G- ~1 P3 L( b+ {3 z
- * @param string $url [请求的URL地址]6 N2 a2 D& Z/ c0 p4 w
- * @param string $params [请求的参数]$ p$ u% B2 x Q5 N$ j: F
- * @param int $ipost [是否采用POST形式]: ]. \3 g: V( ~& i4 U$ ]
- * @return string, B5 x& ?8 q6 Q: h
- */
6 |4 q( G4 ~7 n5 M/ t0 R - function juhecurl($url,$params=false,$ispost=0){& w; w) {/ x3 Q+ s( u" J
- $httpInfo = array();
. i( g9 q* w5 u0 a - $ch = curl_init();8 N$ }, _- [: B' e0 t; ~' N
- 3 U9 ]. K7 e! \2 U
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );3 v3 t( b- [; ^; A0 m/ b! j
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );$ g* E E' R, }8 \$ Q. @; l8 r! J; W- Y
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );1 \/ d+ _" M3 O+ Q9 P
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
( k9 J5 y6 d1 Z2 {2 j# ]9 z - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );' W3 b, `" l8 q' h. v8 u" d0 }
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);9 k* \; ? k1 a _/ k) u
- if( $ispost )
" a/ F9 f( \0 ]4 d0 R - {% [$ O5 e- m6 J) m
- curl_setopt( $ch , CURLOPT_POST , true );. K I8 e- y: u9 ^+ P3 o- B
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );1 g: R8 L. Y# C: ^3 Q& F
- curl_setopt( $ch , CURLOPT_URL , $url );
5 ]' _- e! W Z0 O% H8 @$ Q8 _0 \" ] - }* \4 t4 G7 x# x% S0 U
- else
+ t8 H. o$ b# W0 y. x. Q+ @ - {
4 g$ ]/ J( c4 X; x& a - if($params){( d. q( }" H* A
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
1 Q& _* M; D ?) C3 S+ U - }else{
1 V7 ? r- a5 ` - curl_setopt( $ch , CURLOPT_URL , $url);
( x% `2 _3 n/ T) g - }* G6 _% a! G3 o0 v
- }
; y0 ~2 B- H$ m( i ?+ B - $response = curl_exec( $ch );; A8 v) `% D8 e% p
- if ($response === FALSE) {
" ~% P) M/ M$ T1 Q2 P - //echo "cURL Error: " . curl_error($ch);( B) r7 p- k2 s0 v8 e7 E. \
- return false;
2 f9 A* H E8 A5 q# H3 Q - }, ^7 |; M! q3 L9 y4 |6 e
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );9 M0 q, M/ j% q6 M
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
. q2 P' p, B+ P N# E% h - curl_close( $ch );
* A/ X5 [# l9 ] - return $response;
# V$ c0 f: ]; Z$ V) O6 R - }
复制代码 6 y/ H# x) c4 u/ `: r( N2 c& j' z& f
; g: j$ k' u6 L/ U; } |
|