管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
+ ^; M/ C6 x) B" P, y' g1 k$ q1.添加商品信息
# c P( I% \( h2.添加图片
( w2 }- h% Q/ A3.查询所有产品( \6 @8 ~) I/ d/ d: ]# s0 |
4.查询某个具体产品信息
( f. [$ I4 `( H4 N, |5.删除某个产品
2 q( ^2 [: z% U8 f' _6 c9 c+ @6.删除图片6 n, t( N1 b* A. I$ z
7.图像识别
" ~( o+ W' U4 O
5 G# m6 K+ X, b" J4 S; R. t4 V图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey2 Y5 V$ U( s' g. }8 V
/ X: u6 e9 \/ D8 `1 m8 p4 XPHP示例:; q( O, E2 d0 k2 c
- <!--?php
; N- {% V4 ]8 @. |7 l, ^3 h6 W P- F - // +----------------------------------------------------------------------+ D- F# _+ i. K7 E( ]/ A
- // | JuhePHP [ NO ZUO NO DIE ]9 a5 s7 I7 U2 H5 y# @) U
- // +----------------------------------------------------------------------
( a# p' \* j' L$ D1 b/ { - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.5 i# [5 j7 E' ~! e: l" \/ s
- // +----------------------------------------------------------------------
5 R9 `3 V' J1 i9 C8 J" j( `6 p - // | Author: Juhedata <info@juhe.cn-->5 K0 U1 n! q% f
- // +----------------------------------------------------------------------
8 G: t7 v$ Y. K$ ~6 l - . \: u% j1 m$ Y8 U8 _& v0 o
- //----------------------------------) ` h$ x7 H8 f7 |# t7 C
- // 图像识别调用示例代码 - 聚合数据6 T; S: B& P4 e# ~, i, f: s% s
- // 在线接口文档:http://www.juhe.cn/docs/117
- ^5 Y V$ c: f- @+ O. V8 z - //----------------------------------
" h3 x9 A1 P# \# G - + d7 P0 w0 ?; B: J1 f3 h
- header('Content-type:text/html;charset=utf-8');
0 {8 e4 q; ~% j; K% O* \ - ; e$ o- O4 x: ^1 u6 s
-
& |0 x- e/ }2 H2 M2 g/ W! u - //配置您申请的appkey
- a3 i2 ?1 O7 @- r7 Z) E - $appkey = "*********************";" _2 R. c. u6 Y4 T( j5 K9 X6 q
-
|+ q& c( J; K5 n. Z; ]: r - " m* s" H& }5 ?3 ?5 E( ?
-
s) M% G5 |; _: k+ x3 m - 1 z# q; k. z `! n* `5 x: ~
- //************1.图像上传************
9 H: `& n4 h. _3 g) B. V - $url = "http://japi.juhe.cn/image_recognition/upload";
: Z3 N& ^ C1 m# O - $params = array(
' ~8 |0 B+ s6 k9 ~ R8 S( I% T' B - "file" => "",//上传的单张图片
+ ^. {* L! b$ {7 x' I& R3 O - "key" => $appkey,//APP Key0 ^, T2 b A/ v# Y7 G/ o: P
- "pname" => "",//包名
) B# ]6 z6 K+ N Y - );8 c0 x) E. S; K. x* s
- $paramstring = http_build_query($params);8 A9 {+ m3 w; C
- $content = juhecurl($url,$paramstring,1);0 z/ ]1 \9 K, x* A+ s9 I; c
- $result = json_decode($content,true);- n' x( l6 P7 L! }9 m; R
- if($result){& i9 v R% e$ ?3 V3 z" W
- if($result['error_code']=='0'){
, O! z `& W+ V5 w* B \ - print_r($result);3 M1 Z: _7 `' k4 X
- }else{# Z& |$ B. l# |/ ~/ @. O4 W
- echo $result['error_code'].":".$result['reason'];1 g! |# h: t6 O8 _7 k$ Z, f2 {! z
- }
' o3 L, S# {' `. h - }else{8 V$ N' _4 v- B+ ^8 U
- echo "请求失败";5 c! V% K2 ]3 j, S7 M$ F1 }+ s
- }1 m3 n4 q) O! X. Q
- //**************************************************
9 k. U6 }8 V5 K9 C, O, |4 S: Q - 8 n- d2 p) j5 g( i
- # `9 ^1 n3 n% i9 b3 U4 Y
- 0 t$ G1 B6 _* m* J J1 {5 C
- ! y! k$ K5 w) K+ H1 r' z) U0 N; J
- //************2.查寻上传图像信息************3 R* f' L& m/ z8 @+ s
- $url = "http://japi.juhe.cn/image_recognition/findAll";5 S1 [) y! X2 b
- $params = array(
6 a, B# e* @8 } l- m9 e - "key" => $appkey,//APP Key2 T0 r( ?( |# h; c4 n
- );
: D+ g# a# h. z" Y( ?6 D' C; R% B - $paramstring = http_build_query($params);
' m- r$ _5 Z) B- H$ p9 | - $content = juhecurl($url,$paramstring);5 o3 f' u; j1 F6 K
- $result = json_decode($content,true);. h8 I; B0 h- e6 B9 G/ \. j O( }
- if($result){: s; q: f3 \( ~# m9 `) D; G
- if($result['error_code']=='0'){
, L9 q% o2 _4 a; n; Q - print_r($result);
, Z d( h/ l/ X0 N) r2 ?) ? - }else{/ R1 f7 S7 _8 v: A1 k& F
- echo $result['error_code'].":".$result['reason'];: ^% ?2 q/ `( Z0 Q
- }
- T) c! R/ Z) f8 l/ c* t - }else{5 t. O3 u. K* Q, [+ ^3 Z" C
- echo "请求失败";3 u- h y& n6 w$ | Z6 }6 \
- }# X6 }, f+ t b$ w" k' d
- //**************************************************& r* \: r- R2 ~( w# H
-
' s/ ^9 U/ d4 f% C - H0 G5 }0 y; C7 w
-
$ j9 t1 t5 L1 ` -
1 f( a* K: T6 Z' g$ D4 t. i- U/ G - //************3.删除图像信息************
$ T; l! [$ l4 I) l K$ q- S, [ - $url = "http://japi.juhe.cn/image_recognition/delete";5 R! I! k5 R( P; P3 J: n
- $params = array(
; p0 ?9 B$ ^; A/ r3 I - "key" => $appkey,//APP Key
2 o" Q2 O7 Q7 \' `0 h" q/ } - "imageId" => "",//图片ID6 V ^! T6 X) b+ k
- );4 V; n8 G' k* z) v8 N& L! R5 y
- $paramstring = http_build_query($params);- V5 Q- Q4 t% l6 u' I8 i
- $content = juhecurl($url,$paramstring);
' ^5 F, ^* d+ T- r - $result = json_decode($content,true);$ _$ T& ` K. W( i/ ^! L
- if($result){4 R$ P3 x. M0 i) X5 N4 D- w" B
- if($result['error_code']=='0'){& n% h# ^8 P1 [. a" p4 T" N6 G
- print_r($result);
2 f+ N' m9 t' V+ x9 w- e# @ - }else{
. F/ r9 o& a* E/ N- R7 X- c - echo $result['error_code'].":".$result['reason'];
q: P0 J6 |0 c2 R+ }0 ^ - }1 w2 s3 [7 l) ?- B$ m) {
- }else{1 h; h* q) k* j3 x8 X. }
- echo "请求失败";% T. ?' P: W8 z* Z( f V
- }2 V3 f m# d0 k8 z
- //**************************************************
: _7 Q. v+ Y3 |/ i: A -
& u* N" Y% Q* c; k - - l: |; t# R1 e0 M: e
- 1 t) f& w& o" L, m# m
- J) W! F- f( L) X$ Z
- //************4.图像识别************' z9 a, u% R0 T$ L, Z
- $url = "http://japi.juhe.cn/image_recognition/check";
6 b" w' H- l* N6 h- l - $params = array(
7 o/ e2 q. Z5 {( O' q) T. z - "file" => "",//上传的图片
0 D* q% Z* n) p! E - "key" => $appkey,//APP Key
* I x, G& q y# r3 n3 b& v$ v& h - "pname" => "",//包名4 o* l. F* Q# ^- |4 L4 ~* m
- "device_name" => "",//设备名称(如android OS或iphone OS)
4 ]: Q k$ o/ [ - "device_version" => "",//设备版本(如:4.0.3)
4 J8 E. q" m7 ]# S8 b2 |' G0 \ - "latitude" => "",//纬度. s% F1 ~5 h6 r; |" `' g1 W
- "longitude" => "",//经度8 v2 S% L4 l4 t/ s4 }. m: U
- "uuid" => "",//设备id
) C1 n8 M1 x/ y& x - "zone" => "",//请求地区* f6 K z$ U6 q5 ~, h7 X% Q+ _
- );
9 j2 U% Y) V8 c! r- i. G - $paramstring = http_build_query($params);
$ S/ f/ T; \2 d" k! \ }( Q - $content = juhecurl($url,$paramstring,1);+ z: C5 ^& z7 z0 Z
- $result = json_decode($content,true);
% t7 X8 \9 w- a" @# w& g - if($result){
}: L" v. j! |0 @6 ~0 }/ n - if($result['error_code']=='0'){; V8 M/ H. P& v& Z1 h2 T. }: h' i
- print_r($result);8 Q, O# Z' w: `; |* t, C
- }else{7 O$ {2 @" C( s, b* s7 a
- echo $result['error_code'].":".$result['reason'];7 d3 b! ]* x& n* M; a! N
- }- n9 x- M b# V3 B1 q
- }else{8 ?; n4 [' b# p
- echo "请求失败";
- S) q2 @1 o& ^) q/ F/ ^ - }" A" F1 {, Z$ v" k/ r$ ^
- //**************************************************
/ Y9 q0 M9 v% j) R( Y8 l - , i/ G6 q6 S. y8 \0 x
-
" d: H& t7 b6 {: s0 f" B -
& V( S* Z7 F& W4 T -
4 w" ]9 W2 ^7 W Y - 1 q, b! Z- m: q; \
- /**
1 V. v! i+ C; S8 x. r - * 请求接口返回内容
) i. Q" w# v8 u" K5 C: [) t - * @param string $url [请求的URL地址]6 j& J2 S5 D3 I2 K
- * @param string $params [请求的参数]& e# |0 }, X" R/ }4 k
- * @param int $ipost [是否采用POST形式]
# M/ u! l2 K1 g) z9 d - * @return string- w% h# ~# l6 ?2 S
- */
, h/ n! t- A* L9 Q - function juhecurl($url,$params=false,$ispost=0){- J1 }) F% X+ F' g2 h5 D7 M' N
- $httpInfo = array();4 y- V: ~0 |& Q
- $ch = curl_init();. b+ h- V: f# I; I
- 3 ~" I1 v( T8 O3 K
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );. P2 v ]4 z' f1 A S2 S
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
- C; C3 o& G8 Z7 o2 q- }' X2 s8 j7 J2 A - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
9 L. a* S$ h' H7 ] - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);4 T+ u% A: Z( X/ [. v( `
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );! U- L. e: \/ E- P9 j& {! T- {" p
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);( c5 \3 F8 z& v8 U1 V e0 k
- if( $ispost )! o# C/ Y% N1 o) W
- {
) S% d" b0 Y. N - curl_setopt( $ch , CURLOPT_POST , true );
9 N) @/ \9 W1 j - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );( y! Y, B4 G: P/ A
- curl_setopt( $ch , CURLOPT_URL , $url );1 J# Y8 ?/ Z7 P9 }
- }+ c. p6 p7 M8 D9 j) m' T8 w
- else
" U7 w& T" }, r' B. u, E8 J - { ^$ I2 J6 X' p/ o: }2 G
- if($params){8 z7 F& y% |8 \3 z
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
) Z M7 P( j0 `" R6 t - }else{' M% C: b, `) R7 A! v2 j
- curl_setopt( $ch , CURLOPT_URL , $url);
) C! Z# K: t( P$ Y - }+ X4 z) A! a$ R$ u
- }
5 z" |' V, P4 m - $response = curl_exec( $ch );
; h' O+ {. p" f3 y6 ]6 R - if ($response === FALSE) {
0 c6 C8 D; N2 T2 u% @$ J* D - //echo "cURL Error: " . curl_error($ch);
9 ?8 i1 Z8 r6 A. Z9 B+ N. Y - return false;
) r3 A8 T A! `9 I' h& i \ - }6 C& r `: y+ t) L0 \/ n! H
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );/ V8 J2 d9 K, G: ^% k
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
: Y8 C8 ^4 t* q; G" A5 a1 G0 \8 } - curl_close( $ch );( n' H! \+ S& p& v2 ^. `7 w. ?! z
- return $response;
( q0 Y9 k0 L5 v' E - }
复制代码
# P1 e4 F. b; Z& X f" r$ t$ [$ |7 D! `; ]7 h
|
|