管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。7 z3 T( H: j2 E* y) d9 |
1.添加商品信息
3 R3 I# {6 x: N! U2.添加图片
% ~% G# c: E1 F; n1 O) T4 r3.查询所有产品, q9 D+ R9 V C
4.查询某个具体产品信息$ e8 Q6 O5 S: [- \( [' w* e7 y. a S( o
5.删除某个产品2 k/ M0 S% B" ?7 O/ ~
6.删除图片7 C$ t4 z s( W
7.图像识别. P* x- i' t; Z( ?; K
4 O& ]1 k/ H5 K- h2 C; w
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey! ?( y3 O8 E3 b+ a! {
" f: x/ V% q8 F% ~3 o. C, RPHP示例:6 a& V9 ~( e/ Q& l: b+ N- [) k3 u) `
- <!--?php& W$ B/ U3 I) k% X- j d
- // +----------------------------------------------------------------------+ i8 F3 n6 |+ H# {! o
- // | JuhePHP [ NO ZUO NO DIE ]0 ?' _- R. x3 \. H; B( G ~
- // +----------------------------------------------------------------------
, x* Z7 ` j* ]$ Q: v# f - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.& V( y) B1 k8 O( p
- // +----------------------------------------------------------------------9 r9 l+ ]9 |! M, ~
- // | Author: Juhedata <info@juhe.cn-->
- o- o5 k& K1 P* b" u - // +----------------------------------------------------------------------
$ U5 \9 }2 p" x* h/ L -
- w4 y& e( r2 B - //----------------------------------
8 M+ q5 x8 _$ r% l. V. d* G' Y( Z+ Y - // 图像识别调用示例代码 - 聚合数据* i8 A$ A e" d9 M" i. }
- // 在线接口文档:http://www.juhe.cn/docs/117( k& u. y- S" {& t" I) h- p
- //----------------------------------% g* A9 f4 T) Q4 h( ?; N' \
- 1 E. E& Q8 U# N8 Z
- header('Content-type:text/html;charset=utf-8');7 E+ G1 L$ U8 Y+ t( K9 G5 \ |3 ~: ~+ r
- ) v' T, R6 I/ B8 H- Z1 I( S5 p' P, \
-
( l* y6 T1 Y$ A0 B* Q- m* F' R - //配置您申请的appkey3 F8 j& O) t7 Y1 r9 ~
- $appkey = "*********************";
( L C% M/ R( z -
5 r3 q3 h& C; y5 G6 g' S; y8 T' B -
& L0 s8 @- x+ D$ f) @4 u' P1 _0 e - 2 V" D: a+ W* B9 q0 n* B
-
" y. L. \+ a4 p2 I* a0 D' ] - //************1.图像上传************( N4 S+ Q$ J3 B. Y# s0 j
- $url = "http://japi.juhe.cn/image_recognition/upload";5 L! ~+ M) q$ a# g
- $params = array(
" e& T8 F$ X3 ] - "file" => "",//上传的单张图片" F# U! X4 B; W! A2 f* c$ W
- "key" => $appkey,//APP Key: r2 `4 J- s8 x/ Q& o L( }
- "pname" => "",//包名3 Y0 a1 m/ Z" G6 m9 D" P" e* z: V0 \1 C
- );
+ U& l+ s: L4 `0 q5 F# ` - $paramstring = http_build_query($params);
3 c# [4 {% G4 A5 s+ F9 C* O: @; s4 E - $content = juhecurl($url,$paramstring,1);
7 L1 L# n, |% J8 F7 F - $result = json_decode($content,true);$ Y4 ?4 P/ O3 j9 n! i$ S3 U4 T
- if($result){
$ U5 p2 E7 n1 _* ~/ Z - if($result['error_code']=='0'){
, D' X/ R$ s# i6 D) n - print_r($result);* z+ Z. d8 |! P1 V
- }else{3 K, \; O4 s) a. C% V
- echo $result['error_code'].":".$result['reason'];
6 ^( ^0 u9 H! a0 } - }
$ o$ D3 ^& z! N# ^' c - }else{6 R; T# `; V. b. Y- k2 A
- echo "请求失败";9 b0 A+ Q$ B& F. ]: C. X9 X6 s4 [5 |
- }1 t, B: e* O& z& K
- //**************************************************
8 I) Q5 x+ x- d9 N7 m. Z - % v6 g8 V1 T3 r7 G# k
-
, L- E; b3 B$ G$ A - 5 Z3 m6 g$ K; j4 m9 q' R, C* @
-
9 c; x% G5 S6 P4 @6 k- f - //************2.查寻上传图像信息************6 {& I: n8 Q8 r
- $url = "http://japi.juhe.cn/image_recognition/findAll";+ d4 |( j8 @6 B ~* H4 ?9 _$ N
- $params = array(: ^) R0 y/ [( D/ a9 d
- "key" => $appkey,//APP Key
+ P% a7 U' ?1 d v2 c. `$ ] - );
7 l% {* i+ g+ N/ l. r% v d; E - $paramstring = http_build_query($params);( M4 h+ ?( E% |- l: O) C, x
- $content = juhecurl($url,$paramstring);( A9 ^4 H, B- O! z3 [9 Y' T' ~9 s5 ?$ T
- $result = json_decode($content,true);3 s- V7 o' ]1 n% ~0 ?
- if($result){
' G" |5 l& d( k, _ - if($result['error_code']=='0'){5 ? Z3 D' {; s4 P
- print_r($result);3 a9 i# }, A: n# }+ W- K& N6 G' M
- }else{1 }' W% q6 |) W q) H
- echo $result['error_code'].":".$result['reason'];0 e0 d: N& Z! C }
- }
. q. H7 e# O3 O- Y - }else{
$ x% M/ a% j' u% n - echo "请求失败";
$ G# i6 o. f6 z$ `1 I+ r; ^ - }
4 B- U. c/ u; k. E2 k# Y5 H - //**************************************************# ?+ L8 Z+ S8 t0 r3 c* ^$ g
-
; r; d0 r; H: T, j0 E0 l% E4 C -
8 t: d) f+ l' @1 r V. \: g1 h - 1 I% V5 Q! a0 R0 S8 c! k
-
% ], W, E, P3 L" t, S! V - //************3.删除图像信息************
u; S( N" C! }* R" ~ - $url = "http://japi.juhe.cn/image_recognition/delete";
1 @1 m' [) r( x - $params = array(
/ C( @7 Y1 M0 M. @ - "key" => $appkey,//APP Key* T; U* {$ v* \2 o
- "imageId" => "",//图片ID! I/ Z8 B9 C* C" F
- );
- N! D* f% { J! S - $paramstring = http_build_query($params);- H% H! M1 G1 E5 s
- $content = juhecurl($url,$paramstring);
4 k" b* }2 m2 v+ z8 D2 y2 s - $result = json_decode($content,true);
: n2 L# W, ? O: W' M - if($result){; P1 s4 I- p* x) R2 Z1 h
- if($result['error_code']=='0'){
# N; Z: {/ t) x; K - print_r($result);$ z4 f( y8 Z6 W6 ~; V% `5 ~
- }else{- ~6 f9 d2 S) ~
- echo $result['error_code'].":".$result['reason'];
" S* f4 v; u( Y7 l7 t4 W - }
6 d8 x- k) k0 Y; d) C2 D+ s& S8 m. x - }else{
! Z4 @; S, t7 n, k& b6 \ - echo "请求失败";" f! B6 x9 I! }6 @; j1 C
- }5 u' s" f% S @, k. k& p* p: g6 Y
- //**************************************************$ |. G Q2 D9 {: A3 ?
-
5 |" D+ N# \3 W. H% _3 C6 m( o3 ? - 4 v! R1 Z1 [8 O
-
X! O: b, [" I+ ]$ J - 6 w, R0 F2 F; ^! }- j! E+ N
- //************4.图像识别************! R* t, Y; ^$ }4 x6 O
- $url = "http://japi.juhe.cn/image_recognition/check"; i G" n' Q, B
- $params = array(
; G$ F; u5 @& w7 k: `* j5 ^ - "file" => "",//上传的图片2 T) ^5 J' w0 p5 s
- "key" => $appkey,//APP Key) I/ A- k A3 g& s0 {
- "pname" => "",//包名" @# l6 |! B8 D0 x; S. y8 z
- "device_name" => "",//设备名称(如android OS或iphone OS). X1 ?: ~! \9 x7 ]' |5 A& e* z- |
- "device_version" => "",//设备版本(如:4.0.3)
8 X! b- y( b* h P& W - "latitude" => "",//纬度/ H- x! Q: _4 q3 x
- "longitude" => "",//经度
: i* H, W! m; j! o6 P - "uuid" => "",//设备id- r9 n2 c2 N# S+ p4 t( C& k+ Q
- "zone" => "",//请求地区& ~, w2 ~7 C/ _9 N
- );
z& O& R- H9 J$ G - $paramstring = http_build_query($params);
) v2 i1 O2 {. |. g8 ?1 m - $content = juhecurl($url,$paramstring,1);4 G' ]: W2 S# f7 K9 b& M6 g! E
- $result = json_decode($content,true);6 y0 x+ o2 v. K2 y: U8 k! j
- if($result){
' D5 {# Z- }' k* D# u, e - if($result['error_code']=='0'){$ v5 D6 N) Z" o; Z
- print_r($result);* j5 ]# J% |! U; j
- }else{
+ X0 X* i8 |2 w8 Z6 A - echo $result['error_code'].":".$result['reason'];- W L) }+ |6 c) g n! l
- }3 ~$ U4 l5 i. j( _$ N' G2 [
- }else{; m: S- W3 R/ i3 `( v( T
- echo "请求失败";
/ C1 ~8 U2 m2 z) U2 \ - }
0 a9 L Y7 l+ {( [# O( P2 y7 k - //**************************************************" d4 {& s& e3 u9 E/ J% B* M
-
. a0 c$ ^# \5 o. {6 }% f- \ -
$ q4 J6 p3 a9 n( M( f8 D# Q - : Q! R) X' K2 W) |
-
, j8 R1 t( [0 [" ~9 `7 K$ b -
1 T. f* f# ]1 _% ]- t( U: O. x9 J2 T - /**
7 o! R; F1 T5 p - * 请求接口返回内容
# `6 U1 v; d4 X) G - * @param string $url [请求的URL地址]
9 }8 B: |( ~( l' J - * @param string $params [请求的参数]0 N& L/ a% B* P, T
- * @param int $ipost [是否采用POST形式]
. z: ?- D- I. l0 @ - * @return string% H: V$ Z4 d5 g L8 o
- */6 B, Q' O( _6 c9 h9 H9 d
- function juhecurl($url,$params=false,$ispost=0){, Y5 d4 R7 p8 b3 \7 s& a
- $httpInfo = array();, C1 |. d0 q1 n, F6 \
- $ch = curl_init();
; W# e: B( o3 H$ Z - 8 |8 c7 {/ V3 {4 g+ G! D; [- L
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); y: S0 a9 Y6 M: ^; M
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
% Z8 D. ?. _, f t' r - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );- f/ T) t+ o* U' `4 P |
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
; e4 E& [. ?- g) I; B; H - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );1 Z; ~( w# D s) `) B2 y
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);. Y8 z7 G; l' q) k) q) B5 J5 I
- if( $ispost )( N+ _ H% t% g# @, T- H
- {" c6 ]1 t, D& o
- curl_setopt( $ch , CURLOPT_POST , true );
0 @% a7 Y: Y; i: T8 i/ t: N3 d$ k - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
; S/ P4 k6 s; q: W1 Y2 H - curl_setopt( $ch , CURLOPT_URL , $url );
: U7 e9 ?4 ]5 x& m+ ~" g4 ]# y - }5 o5 X% k9 E, Y; a4 b4 K/ p
- else. D5 W, c( `$ l: @( D
- {) w- G r+ S+ k6 T& i6 j/ I
- if($params){
$ a% u% T7 U% K% x - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); O# W8 }/ g" Y
- }else{- s% x# X! @# M5 {
- curl_setopt( $ch , CURLOPT_URL , $url);
9 {' v5 k0 r; Q* M& Q - }
m" E2 f7 ]3 p - }! l" V3 v8 K! O2 x8 g
- $response = curl_exec( $ch );
+ a3 V& m1 C d( z4 ?3 C: u - if ($response === FALSE) {
! G3 R0 K. X6 P - //echo "cURL Error: " . curl_error($ch);& |5 }) x. I) H' T, S W
- return false;
: z8 S) D* a J - }
! k9 f8 W- Q( I) p5 K( r+ P/ Q - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );; v* J* s" k1 K$ v! n8 S/ Q
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );+ E) H5 p) F, `) J. M
- curl_close( $ch );
6 \+ ~! _. b$ M9 c3 s - return $response;
$ p+ g4 F$ u n( o - }
复制代码
+ D _2 [ B( @ I% N7 c5 J$ j, q5 `2 w: \/ c+ N+ G
|
|