管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。6 [7 O c/ w4 v( n
1.添加商品信息
$ K" w/ d/ \/ Z# C$ L# i- K/ n* ~2.添加图片9 t( n0 f) j" a# _
3.查询所有产品
6 e8 ?7 M1 L) f0 W; X) C7 I4.查询某个具体产品信息+ V7 w5 L2 w- a+ O5 b# \; \ a
5.删除某个产品6 G! Q7 `6 Y: ^$ Q. r5 p- s
6.删除图片
, t9 l( ?! [3 ?+ q0 ]7.图像识别
- G. h) x& r4 h8 R
% t0 I9 H! A4 I# t图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey1 k/ S; O& P3 l4 ^( {# I, d( M6 L
! `0 `, ~5 z, d; i$ D$ H" {: s
PHP示例:) ^9 i8 ]) d- F% X3 E* x
- <!--?php: z9 N) D. y+ f, |4 ^" h
- // +----------------------------------------------------------------------" P' g, f% e+ X) Q3 a' s* k2 o
- // | JuhePHP [ NO ZUO NO DIE ]+ U3 y, i$ i0 r$ ~- ]8 ~
- // +----------------------------------------------------------------------) N/ X: g% O! M4 W
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
( N* V* S2 k. c9 B3 i7 ~( Y - // +----------------------------------------------------------------------- ?8 ~( g' L$ W1 |
- // | Author: Juhedata <info@juhe.cn-->
# T# ]) ]3 E0 S# S) y0 I, p* G - // +----------------------------------------------------------------------
' m5 u" a7 }( W, H - 6 d- B, E b2 k3 R
- //----------------------------------, _- Z1 M& z! Z+ ~
- // 图像识别调用示例代码 - 聚合数据
6 k8 q+ B4 f' {7 t) i. ? - // 在线接口文档:http://www.juhe.cn/docs/117: h/ x- o) m5 {. e( o# P7 d5 d/ P
- //----------------------------------
7 L! X: H- d" }' J, j -
4 J. }. a( R" E9 H; H - header('Content-type:text/html;charset=utf-8');. f6 c5 m* j& l2 n! n0 e, u
-
! O% Q; s2 {. R7 S# _( [* g* i -
- W" F: S# L! I: r- _* ` - //配置您申请的appkey/ ?1 }8 g5 e" c) W
- $appkey = "*********************";
& D9 q- m% l& n5 H' B - 3 N- ~% x8 P, x
-
( W, z& k" D% a - 2 r" U1 L, a, ]6 |( w1 H
-
8 g4 g$ K _1 C; k Y4 {' t" _ - //************1.图像上传************
' W1 I6 f& q d6 L6 y - $url = "http://japi.juhe.cn/image_recognition/upload";, D/ U1 W8 }/ V
- $params = array(
4 N2 \ E P& }4 j2 H) p! f/ @ - "file" => "",//上传的单张图片
& ~; a7 R6 A: O- u, U+ s* K( l - "key" => $appkey,//APP Key+ b6 P+ y7 h( N5 ^$ d0 C
- "pname" => "",//包名
# z* B* S% [9 q5 y9 f5 h - );
& ~/ o& U. O* f+ H7 T - $paramstring = http_build_query($params);0 X: X, P; u( U5 d
- $content = juhecurl($url,$paramstring,1);! m$ s+ [6 `- C& T6 V- p
- $result = json_decode($content,true);
/ f. X3 b, l; }1 f% c8 \ - if($result){
: \% T1 v! o; t! b3 n* Z. D1 ^8 |# j - if($result['error_code']=='0'){
2 @! z9 }! _, P6 m+ I5 o/ O - print_r($result);
+ }5 C: ~1 f" ]/ [ - }else{9 R6 j# X! W7 `6 c
- echo $result['error_code'].":".$result['reason'];, w( S: u3 c, G- K& _3 d* T* K
- }7 q% A, ?9 P/ I: q, H
- }else{. z4 e/ j3 K4 Z% J
- echo "请求失败";
! L" w% x N7 i5 _9 b4 w. J8 D - }
. x4 j3 q5 Y& M8 s# Y: ?6 q2 P - //**************************************************
% }$ Q4 Q2 c/ s% Y- u. H# R2 j" U7 y1 v -
5 ^; f1 r% r' S7 b# [3 B( \' `( V4 s( t -
! u9 y8 Z( Q5 o! G - ( \: |% d% z. J$ @; e8 c9 X, n0 V3 ~
- 6 A$ |& {8 i) {( g- ]
- //************2.查寻上传图像信息************
, A+ @1 p7 ?4 m, \. m0 m9 y - $url = "http://japi.juhe.cn/image_recognition/findAll";: U" m1 y. I' _8 X$ |/ w7 {
- $params = array(
; v+ N- w2 m, S5 C1 M0 l" p' \% x - "key" => $appkey,//APP Key4 f- ^9 {5 `. V& c
- );
\( s h7 g. a5 n" [% C0 b4 ~ - $paramstring = http_build_query($params);
% z* Y8 C. H2 d9 z$ W - $content = juhecurl($url,$paramstring);
1 ?3 c) {3 L+ W1 f: X; W - $result = json_decode($content,true);* b, P0 t+ N+ O, E1 S, m- ~
- if($result){. V+ R2 A0 L: [; }
- if($result['error_code']=='0'){( V: a! b5 p% D
- print_r($result);9 M! ^5 s( F/ s1 _0 V- k4 e4 y
- }else{
& l, a6 ]* ^$ G9 o, S& ] - echo $result['error_code'].":".$result['reason'];3 G1 f7 R6 ~, ^) f/ a7 N: I, |
- }
- Q: }& j4 T7 k) A - }else{0 u: V: o; |7 j
- echo "请求失败";
. z F: M0 P. I0 ]& ^9 C; E4 p - }
$ ~2 E2 P+ o1 q; k0 P p! B - //**************************************************7 l. o5 b: _) T: |0 b
-
1 Q* V3 J- A3 I7 \& e/ \' d - ' G% j: V- |# O1 o* q) p5 J6 m
-
) C: d! H7 c: y: [ - 6 S2 v( X0 z& _+ Q
- //************3.删除图像信息************
: r5 X% ~4 g7 X" ~! @3 A - $url = "http://japi.juhe.cn/image_recognition/delete";- j( o$ v* }% R9 G( Y- Y( G9 q
- $params = array(
" W; c3 I# c1 P6 M3 h# B - "key" => $appkey,//APP Key/ S8 u2 G1 i+ [' F5 f' f/ P* w
- "imageId" => "",//图片ID# z) `4 G! ]. A) f# M \: }+ }7 ~
- );, H* J' b4 N' U! o% w! F
- $paramstring = http_build_query($params);
1 `+ J( c* w9 T1 b [. C: _( s - $content = juhecurl($url,$paramstring);$ Z" N1 q i v
- $result = json_decode($content,true);
1 P! A# f% |! o. u: C% J( a - if($result){9 G- `; ?2 I& |+ Z1 r
- if($result['error_code']=='0'){4 B% }9 ?7 K5 i7 X+ l( C- V$ q6 N
- print_r($result);
& b& {. H$ b# X, p$ C, i: R - }else{
+ @8 B1 I' g- U5 I5 o' d2 Q - echo $result['error_code'].":".$result['reason'];5 d4 h7 N9 ?, S) b2 \
- }
! \& j: }# r2 J- |" f( O. r, @ - }else{
3 A% y, d4 Z0 w+ g% p- X z - echo "请求失败";4 S, s7 _; i9 v% A( v
- }1 Y/ X' f% C* W% P! ?
- //**************************************************
) G- i% X1 p$ C6 V8 v( w" N -
5 I$ p% x: g! g2 J/ c3 G+ x* H -
! V- n7 \3 _! l% w+ l) m - z+ j$ ]* h* s( w# ^( J. d
- ; q3 A( T% [3 I _3 i
- //************4.图像识别************3 r8 Y2 H3 K. |( I' p( ~
- $url = "http://japi.juhe.cn/image_recognition/check";
W3 a7 k/ `; k/ r5 S w+ H - $params = array(' O) W6 N, g, J Z `3 M! Q) ~! M# W
- "file" => "",//上传的图片
% ]7 B b! }1 i+ V& y, x - "key" => $appkey,//APP Key
- K/ R; Y; p# @' p' a x. A0 A - "pname" => "",//包名
4 j0 L: P M9 |$ O( c$ e+ `; g0 p - "device_name" => "",//设备名称(如android OS或iphone OS)
i8 e. }" }& s& g) d* S2 l - "device_version" => "",//设备版本(如:4.0.3)
( s2 ^( ?# O" {5 K$ P - "latitude" => "",//纬度& |2 _+ H3 t$ }% M: d8 q
- "longitude" => "",//经度" W" r3 C$ p+ { M
- "uuid" => "",//设备id$ T! F* l! [) E- Y* V
- "zone" => "",//请求地区
8 e! D8 o. O0 y& V - );) j; D, h' i* k1 z- C6 b0 N8 I% r
- $paramstring = http_build_query($params);; Z. @4 `" L" N& g- Z# V
- $content = juhecurl($url,$paramstring,1);1 e1 r1 j/ ` r) d* o. P
- $result = json_decode($content,true);
2 ?- _- c T4 u( X- U - if($result){) e9 |! c9 H4 L5 k8 F; b$ p& k
- if($result['error_code']=='0'){* D- g/ p6 d- l9 _
- print_r($result);" J+ T" V b% _
- }else{0 j7 a7 I# T% _. f$ k" Z% S3 g9 L
- echo $result['error_code'].":".$result['reason'];6 l$ |% N U& F/ N9 x% I
- }7 S. t F5 g7 c5 m/ A
- }else{( P8 x! o1 L/ k' e5 N; Z
- echo "请求失败";
4 r9 T/ N6 S# a6 T; D - }
9 n e; \) @; a - //**************************************************# u3 ^# ~7 a: K/ U' N! h$ h0 R4 T
-
+ y- v4 J4 b4 R! h -
s- g' }2 ]) N2 ^ - % q5 J* t( }) w* g' |1 t5 k
-
, w6 ^0 Z6 L) [. h - + U2 L4 R7 K) M7 H+ ]! s
- /**
/ T- l! Y: c; ^ T# y% D - * 请求接口返回内容8 }3 s% l, }: g- o7 o6 [
- * @param string $url [请求的URL地址]
* I/ ?1 j8 {1 y8 l# H - * @param string $params [请求的参数]
9 j) |, ?8 O4 P& x* P - * @param int $ipost [是否采用POST形式]. M" l& H* M6 |5 _, s" H
- * @return string* d* S! i! `: T
- */
+ _+ ? w% p3 @ - function juhecurl($url,$params=false,$ispost=0){
! ~; C- {; d+ F. C - $httpInfo = array();' c' m4 J' w8 F. m; k
- $ch = curl_init();3 ~0 t! L9 {+ \2 p3 ]! g: h
- - y9 Y- A0 i2 D
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );) h7 @$ r3 l- A7 ^; D7 P1 P
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
- \. T, x6 ~- ^9 h! Y' g0 }& o3 K. y - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
1 {8 v+ L" j6 r$ J - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
0 A$ j) i& N" \% H* ^: H - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );- Z4 g3 r5 W9 F$ c6 Y' x9 O
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
8 _8 Z2 c' }9 T3 M% X$ l* ?! m8 E - if( $ispost ), a" R) u; a) m9 c; h/ _
- {
9 t- }% t1 r) d - curl_setopt( $ch , CURLOPT_POST , true );
F/ `% E: U0 D7 C - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );0 v: T4 f. T/ L* W( W( R, p0 U
- curl_setopt( $ch , CURLOPT_URL , $url );
' i! ~8 }7 p. G( V7 v3 l, c - }
. j' e7 Q9 Q( F+ h- u: B - else
9 }) H( m1 d8 k* n* S - {
) I8 A; j2 c9 y/ l2 ?; `3 u: Y9 ^ - if($params){
) S2 F" S* n! g+ _: h5 ]3 g - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
w* e+ Q7 h! x - }else{: @( y8 O0 B. M% q
- curl_setopt( $ch , CURLOPT_URL , $url);
% J4 O& c. R8 \( ^& ]9 y0 a, l - }
- u) H6 I; [. `4 m4 s- j" x8 T/ K - }
1 ]% V$ q5 T7 F* P4 ?6 _ - $response = curl_exec( $ch );/ `8 r; a( Y6 o8 C$ H8 `1 Q% j
- if ($response === FALSE) {
( o4 D4 h" |& ^/ H% t) N7 Y - //echo "cURL Error: " . curl_error($ch);4 _3 t, R- f. i. P# f7 C
- return false;
9 t* n. a" B2 |$ o - }
9 o; j! {/ Q5 x7 r1 g$ B - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
' B6 p/ Z, H% @$ C0 E) Q8 t$ K/ y1 u6 w( l7 t - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
0 ^$ c6 u5 T! W/ g; n - curl_close( $ch );
7 I+ {7 K0 }! v* Z. k# ]3 v - return $response;4 d2 d% _& [# M# B3 C0 k* l
- }
复制代码 1 @3 n( D. p. _+ t! B# F9 e
. U+ @9 R7 ?) x/ J |
|