管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
6 T) w1 J( q; n5 a; [, M1.添加商品信息 {6 q) d/ T+ {# ] k9 c3 G
2.添加图片
) M* d' O' o' I8 C( U% i3.查询所有产品
" }) L6 g* d7 Q' F& R4.查询某个具体产品信息
' A- `9 j# L: A$ F, p6 B, a5.删除某个产品
9 O3 Q8 r0 k9 O" D" q+ B6.删除图片
: D5 ^% H) n5 X: l7.图像识别3 ~5 l. J) Z8 z) X7 a4 m. J) W/ o
" A! Z2 O! \+ r K' v* s' x图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey5 X0 I# i4 Y! A1 u1 D" C7 r3 j
0 M/ d" \- U5 t. y$ C8 P1 ePHP示例:
; a) g/ @2 r4 t/ G2 j. ^+ ]- <!--?php
6 _" [! ^; ~8 I: h& d8 X - // +---------------------------------------------------------------------- Z5 Z$ E' n3 _" S6 B2 a
- // | JuhePHP [ NO ZUO NO DIE ]
$ h% j- b1 V, A$ g/ S" F+ P - // +----------------------------------------------------------------------
( l8 C0 c* P+ ^1 e - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.$ @8 o. K! [5 i) n
- // +----------------------------------------------------------------------
. R8 T/ c' P A - // | Author: Juhedata <info@juhe.cn-->
0 m/ a8 z2 F: Z9 ]4 l6 s - // +----------------------------------------------------------------------
; {; n% l& }+ Z9 `* O8 Z4 u1 Y' F -
+ @1 c: L# U* G' }! l8 d$ b - //----------------------------------! }* H4 f1 {5 I T
- // 图像识别调用示例代码 - 聚合数据
, z6 L0 S, \" e, h7 i6 M+ f - // 在线接口文档:http://www.juhe.cn/docs/117
: i4 Z. S# t9 Y7 d7 A4 a2 v - //----------------------------------7 l. u( C- g+ d4 U+ ~, k9 m
- 3 L- _" L# g( g5 L( r5 l& y
- header('Content-type:text/html;charset=utf-8');( F& d7 k- l v( a9 B0 U8 S: A% d8 ?
- $ s# W, \% N: C: l" j$ m1 m% I4 q
-
# D, ^ e" I6 v& o. o - //配置您申请的appkey; O9 r* ]: q w# R3 Q! U2 C
- $appkey = "*********************";
9 H4 Y+ w# Y9 N' a) o1 @6 E2 O - $ ?' R' ^! ?2 Y! _. t D* C3 P
-
+ ?: ]' s! `" i4 } - 2 T: N& N7 e; R( r# G/ m i# U- A
-
! y2 L- ?; P8 L$ t6 B3 ] - //************1.图像上传************; a* _* V4 u; Z1 Q+ I3 ?0 `0 K" U
- $url = "http://japi.juhe.cn/image_recognition/upload";
1 l. @# a: i4 W* r - $params = array(
1 U+ n7 k; `) F+ v' o5 w8 ] - "file" => "",//上传的单张图片, Y% f: i, s( \$ F# Y; w4 [9 ~
- "key" => $appkey,//APP Key8 H; `8 \3 R3 x O
- "pname" => "",//包名
0 X- `# D' O+ i0 ]. w8 _ - );
9 g( z. Q. m1 a5 c" X3 q! d - $paramstring = http_build_query($params);( |8 x. k, [2 p/ L4 u
- $content = juhecurl($url,$paramstring,1);
3 l! [6 W; a- ]) l+ k - $result = json_decode($content,true);
, M$ @6 |3 @4 A( Z- _4 x! j6 U d. v - if($result){
& I+ ?6 S7 D. v& v; o - if($result['error_code']=='0'){ @6 v* \- H |% N4 w
- print_r($result);- f% D: r0 S+ _" Q, `
- }else{+ O' ?3 ^& a1 u% W+ y9 Q
- echo $result['error_code'].":".$result['reason'];
; J0 i1 T, o1 J9 c - }
; x4 k" y0 Z% @. W7 b( P - }else{1 F$ a: h e" @% M& f
- echo "请求失败";
" i- K% y& B+ Z+ h - }
4 M* Y% j) n0 O8 z9 e3 V" X8 r - //**************************************************- D5 d. | C' d, h w
- " K `% D2 E( o5 P
-
. [! c9 _& ?+ D4 Q - ( e* B: T! Y1 X& }4 w$ h" |
-
5 ~3 L, [8 s8 _2 v: }& a; R - //************2.查寻上传图像信息************: N, I9 F$ Q9 Y8 V( D) q9 I
- $url = "http://japi.juhe.cn/image_recognition/findAll";
M+ a8 f" c. d. i$ [9 u$ o - $params = array(
0 X( \ D( y+ B) D, _ - "key" => $appkey,//APP Key. q; E8 }4 ]0 u( K4 w3 w: j
- );+ P2 U: D5 g: _. f7 x {
- $paramstring = http_build_query($params);$ g$ _0 w) I' g5 @6 V- A
- $content = juhecurl($url,$paramstring);
* c& z9 G$ q8 A! ^ - $result = json_decode($content,true);) e% o: M# F& ~" ^0 ?$ @
- if($result){
! l4 c2 v7 g/ ~; X4 e- J# H k+ ]5 F+ l - if($result['error_code']=='0'){
) T/ b$ }% N4 x - print_r($result);- z" n5 y! |" J
- }else{
2 B+ e6 b4 W+ b. Q - echo $result['error_code'].":".$result['reason'];
, e! b# N% Q7 r1 d - }
( `: |- {0 c& i" m. q4 k9 g - }else{4 A# C$ P6 ? A2 g# T: N
- echo "请求失败";
9 l/ [. h: C# B5 C" V" O( k$ T - }
6 Z/ ^: W; h2 C) m% e6 X% L" C - //**************************************************
& N/ ^ G' f, |8 R - ) S" i2 E4 G+ O7 e
- , `+ F' z- c! r5 C: W4 c
- 5 n3 N) j% k6 W7 W
- + w ]/ }3 H0 H4 a" }" _/ J
- //************3.删除图像信息************
! P: q: G) a# a- z' w - $url = "http://japi.juhe.cn/image_recognition/delete";! i% d2 ^( x }
- $params = array(
0 g% u, H* f* W, H% y8 g - "key" => $appkey,//APP Key
3 l! F! B1 u/ X1 W4 E0 A6 y5 y - "imageId" => "",//图片ID
G5 I. y, r& E+ b8 d - );
( C4 B) \' o, V2 j/ w. C - $paramstring = http_build_query($params);: H, l' }3 U i3 W5 a4 y
- $content = juhecurl($url,$paramstring);
, y& z0 x9 C3 ^* ^ - $result = json_decode($content,true);, f2 I7 r0 M0 H
- if($result){9 Q" U2 m1 \1 r
- if($result['error_code']=='0'){# H2 s, _& d, \6 P$ p" |8 l
- print_r($result);$ I! ^5 p% _) f+ Z
- }else{0 C( S- [ E& d' L
- echo $result['error_code'].":".$result['reason'];/ o4 } O8 S1 H% {
- }. ?% ~* l# b: A/ T) ?5 x1 Q- J
- }else{$ H! I; _: g$ j& S/ c# M5 A
- echo "请求失败";4 V4 R) ?. M& q, r
- }
9 I0 G3 M1 y, R1 w" v( K - //**************************************************& z/ f+ N! |7 [4 F) b: v8 y
-
9 T" N# ~/ |+ a1 x% }0 j - ! p* E6 h" |% F% a
- 0 J. q6 w! a6 N/ L( ~2 _0 F& r
- ) G% E% {. g! P- v
- //************4.图像识别************& U, n2 @3 Q b$ F
- $url = "http://japi.juhe.cn/image_recognition/check";
4 ?9 i! W1 z, p7 L5 i4 d9 N4 L - $params = array(
9 V% d& a, m) g3 b( @3 ?/ O - "file" => "",//上传的图片+ y- l0 [/ _; o0 e: L6 B
- "key" => $appkey,//APP Key/ Y9 x" V5 U( d: }( r! ^* r# F2 f8 G
- "pname" => "",//包名
9 ]4 j, T! n8 [, J1 e3 R - "device_name" => "",//设备名称(如android OS或iphone OS)
3 L* \6 l$ E* j \ - "device_version" => "",//设备版本(如:4.0.3)
! I j, U. X: I( _- Q - "latitude" => "",//纬度
) P2 q0 W) `! u! F$ N- E - "longitude" => "",//经度* d) e% O: Y: x: @
- "uuid" => "",//设备id
1 v( n7 E7 R- q9 u5 o - "zone" => "",//请求地区
6 Y% m( Y% f$ N; ^3 |7 u1 U - );
4 e6 F" `' m3 Y - $paramstring = http_build_query($params);* e& G& t5 p5 k- t7 C' [, Q) |
- $content = juhecurl($url,$paramstring,1);; A3 K3 W1 q7 e7 c; P* L- ^
- $result = json_decode($content,true);* b$ T I& m2 M' w( Z* W8 |' j
- if($result){
% t6 X' p- u7 _) O - if($result['error_code']=='0'){( t+ \) T7 k$ @
- print_r($result);
& ^5 D" P0 k' a( F1 y2 L - }else{$ e; T; e" Z. }$ f7 [4 r/ Y
- echo $result['error_code'].":".$result['reason'];
7 _$ i3 d* ?$ B4 `& X% J8 S - }
, T3 Q, \9 ]$ F% O# N - }else{& f2 f; l# q. [
- echo "请求失败";
* m4 a+ g% U p6 a% M - }8 a6 R9 D% f) I% s/ A5 g
- //**************************************************3 W3 D7 B0 B% _- z+ z o
- / J+ Y+ k# x* y. v6 E9 w: ^1 ?
- # F) I' G0 b( |: K* t
-
8 i _# ?: |/ q2 b% H8 b - " K+ ?1 d4 N3 a
- ' ]% ^9 N. H* G" N) H0 e
- /**& Z c5 Q' l `6 H9 n' u8 g
- * 请求接口返回内容% V: ]5 Q4 U" E7 u, l ?! u
- * @param string $url [请求的URL地址]7 [" |/ q/ w- e8 G1 v
- * @param string $params [请求的参数]
2 q9 |$ L5 Y2 D - * @param int $ipost [是否采用POST形式]
% R y% u9 g& q9 u9 ?6 @4 N - * @return string/ h" d# W0 u P6 R: g }: ?
- */
& y5 p' q! T6 D' @+ m/ r4 Q - function juhecurl($url,$params=false,$ispost=0){# t' n. U: P; j/ {, [! [6 ?3 V1 \
- $httpInfo = array();
m& C, O! w* {, c0 Q1 n/ w# _+ h7 _ - $ch = curl_init();) g/ |8 S1 X" [- D# ~3 T' g
- 6 E1 S, S c' i3 ~0 H" ` {
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
; e- x/ |* k2 [: d - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' ); M! G# h/ ?, P9 _, c& g
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
* c2 _) W9 J4 D1 f q; C" r - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);* q3 T3 M1 s8 ?: w: o/ u
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );5 y, s8 f+ h! T, Y- \
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
) H$ l- n- `1 ?- z - if( $ispost )
T$ h o+ n4 S" r7 F - {2 O7 {1 ~& b$ G8 X2 ~. v' Y" K
- curl_setopt( $ch , CURLOPT_POST , true );! B2 I5 I- J3 K# g! o
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );/ a [; Y, l7 W7 ~1 O& z5 t9 l* W$ m
- curl_setopt( $ch , CURLOPT_URL , $url );
8 j1 X I0 a, g' S' Q - }) ], h- {- P1 \3 @$ B7 c" [
- else* R# P0 Z$ y9 @0 {, p- L5 ^+ o
- {1 J3 Z$ c: Q% z( T8 F' q2 \$ b, R
- if($params){1 v: Z; l0 P# y0 G( ^
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
, e3 Z# {8 Y9 B0 }8 c( A0 D$ P - }else{" T; N2 ~# ], ?# ]$ i
- curl_setopt( $ch , CURLOPT_URL , $url);2 `$ Z ~4 F7 z
- }) `) |5 E5 o- T) J# Z, | U9 M
- }
1 u4 Z1 m( c& m5 R0 Z# w) q - $response = curl_exec( $ch );. m0 [, r h9 b* x/ p6 p7 T. g2 u
- if ($response === FALSE) {# n" w6 q0 r. T- U- ^8 ^
- //echo "cURL Error: " . curl_error($ch);
! A' y+ ~1 g1 j( i - return false;/ n4 T0 N/ Y, r* x4 M9 v& p: A( y6 \+ C
- }% w" T# A# p& P; Z/ L7 \5 y
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );4 K5 p1 X% V- z6 n
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );6 i- |+ N# \4 K& U
- curl_close( $ch );
. o3 g! M. f" b; Z& {. r - return $response;* ~ H6 a% Y; j# k; W
- }
复制代码
# F; u" v- r' f( Z X2 T
% P& U" j( m6 W: i |
|