管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。: F0 w" Q7 }3 Y7 ]; s
1.添加商品信息+ x8 ]. e& O4 u( ~0 @
2.添加图片3 a% J+ C' G( L' `- J( d0 O8 w
3.查询所有产品: n5 z" m) f. r
4.查询某个具体产品信息
' C' V: {& d- S5.删除某个产品
: S1 U& H* F$ Y+ E3 _6.删除图片4 S X' A. t1 H
7.图像识别. i6 o, W. f& r/ {- q
( r, A: r) c8 B) ]4 b+ O: c
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey6 ]) _0 p/ K; G* m
% G' g9 B9 ?0 Q9 s' y/ m* ^" B7 oPHP示例:
9 w+ \- u- y/ t7 Y. X: D- <!--?php
9 P- `* m, p `$ X, o. L - // +----------------------------------------------------------------------; v3 }; |5 W: L) J
- // | JuhePHP [ NO ZUO NO DIE ]
/ C$ I" c- ^0 m. k" o - // +----------------------------------------------------------------------
0 x# _9 k: B. N4 ~1 z9 l - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
( B/ e/ |' c L+ r - // +----------------------------------------------------------------------
6 c: @. w5 R- ] - // | Author: Juhedata <info@juhe.cn-->4 U/ i2 `( W) |7 T# Z. C3 n( w
- // +----------------------------------------------------------------------
' e6 T4 h" T1 u! c8 O - . o/ `; u6 S) }! S+ y% I% M3 G
- //----------------------------------
1 l4 ?! E& a. v0 p" k4 N" f$ ~ - // 图像识别调用示例代码 - 聚合数据4 E+ R% Q8 L9 v# l
- // 在线接口文档:http://www.juhe.cn/docs/117
; b' `( t' w, @5 f F8 f7 t5 b - //----------------------------------
% k( n, O, B# q7 B* n) o9 S - # A" }1 K/ P6 q4 b
- header('Content-type:text/html;charset=utf-8');
A# @/ u x* I3 Y" c& E -
5 j& b# l/ Z) T1 f -
4 J# q6 F8 d/ Q6 ?0 s - //配置您申请的appkey
1 m4 U2 r' w0 N- c6 F - $appkey = "*********************";
/ s5 a0 ^$ o! ]( C5 O8 l - : r( p/ n0 c+ e* m1 D8 a# a9 i
-
2 L' @: y- g$ b3 l. y - 8 ^9 G1 m+ ]. l8 V: E
-
0 R8 M' o T" W/ w6 x/ @ - //************1.图像上传************
5 d; ^& K% d2 L# f y2 i - $url = "http://japi.juhe.cn/image_recognition/upload";
, w) b# r6 I- ]/ i+ ^# U - $params = array($ }: p5 I; Z f1 e
- "file" => "",//上传的单张图片# s. T% d# g- \+ i7 x6 \
- "key" => $appkey,//APP Key/ ~* p ?* R5 E! b, \9 L3 a
- "pname" => "",//包名7 d1 z. \; s; ?9 v d! X) O
- ); U7 k+ P4 L$ E3 S- u
- $paramstring = http_build_query($params);
% X! _7 Q8 M* q$ v - $content = juhecurl($url,$paramstring,1);
, g8 z' h8 U# L0 I - $result = json_decode($content,true);
3 x/ C& h& P) `! ^- t) a - if($result){
" Q- @9 l! I [9 [5 e H$ u7 Z8 a8 F - if($result['error_code']=='0'){& ?! h0 b0 w* h: T# V5 \
- print_r($result);
( A" W7 W) `& d( ~ - }else{9 T+ j. {5 F9 G4 R% Z5 d
- echo $result['error_code'].":".$result['reason'];
- c3 ~, E: q) G - }7 I$ F9 s7 @$ X! H; W; e* Y& f
- }else{8 }& c, {* C/ O$ x
- echo "请求失败";
Q% U3 H$ k' p; K - }( U" ?# a4 z* t l- p8 K+ {+ m$ x
- //**************************************************$ x( R6 P4 Q$ z1 ^
-
4 \5 d) h. s7 J8 U6 c - , k5 e$ m) U8 y4 D; @) u
- g; `( |) l. |: M t
- * @% X8 d7 x2 V* j- C
- //************2.查寻上传图像信息************- v. l6 y: Y- B3 u! J. t
- $url = "http://japi.juhe.cn/image_recognition/findAll";
1 u1 Y$ X" A+ b% d - $params = array(' T# S; ?7 K- w/ X5 _
- "key" => $appkey,//APP Key
' D* Z7 u7 w a' M, B' R: S - );' c8 P8 K' n5 H, [$ j
- $paramstring = http_build_query($params);( i, J. p( h& e8 H
- $content = juhecurl($url,$paramstring);/ x3 X/ `4 f3 x* A+ ^# g3 g
- $result = json_decode($content,true);; s7 y9 r, D+ ]$ b+ ^5 B
- if($result){- h" N3 f/ f/ n7 b
- if($result['error_code']=='0'){, h ]9 U% T: M% d0 t: @/ |; {+ L9 Y
- print_r($result);+ Q2 ]' H" p k F3 C/ A
- }else{; a* g% ~- D" O
- echo $result['error_code'].":".$result['reason'];
* \, e$ [+ k4 h/ x3 |7 {5 u - }
w5 {: J) F( k; i' t9 e - }else{
- T9 Q+ O5 K3 C, j( h% ` - echo "请求失败";
) ~ Q- W* J( m2 Y7 r ? - }# d5 u6 c' l! A* }3 y
- //**************************************************
! R4 N2 e# F3 }6 w( [2 L - g: o4 c& ?9 @+ u
-
8 A) c$ B- G; i/ P+ l e! i+ V8 y -
" n4 p) d: w& F& y8 i - 4 F3 t/ ^* C" t7 f4 S4 g- Y
- //************3.删除图像信息************
* w4 k- l& w3 H$ q' g& O* d - $url = "http://japi.juhe.cn/image_recognition/delete";
8 [ J& C" K% r9 _, G! P( } - $params = array(- Y! c3 A& _$ Q/ }
- "key" => $appkey,//APP Key
6 e4 h g( b- A/ R) A - "imageId" => "",//图片ID
1 \# k) a; r) D - );: P% g. @ B9 p5 J k* u) n3 b" V- |
- $paramstring = http_build_query($params);
) _- i& K4 s: ]/ R1 f! h6 R - $content = juhecurl($url,$paramstring);
' Q# \+ g8 o; Q( s- y$ T - $result = json_decode($content,true);3 E, ]2 L- v) S9 d
- if($result){
6 h% J+ M2 u9 {4 d5 N4 J - if($result['error_code']=='0'){0 K9 O: i/ S) v @8 y9 ~
- print_r($result);
5 g z6 L3 }: o* u( B" |; W: L8 t* H - }else{; T/ T; | h; P2 Q
- echo $result['error_code'].":".$result['reason']; d6 }7 Z7 T4 O) o- c. _
- }+ I) g* `! l! ?" U
- }else{
' I0 g# t- I3 `; b- f - echo "请求失败";
3 W" f0 s; b3 u% ` - }% p- a* c8 p, u5 N
- //**************************************************
- p! m- b$ E/ r! a( n. x' i -
+ s0 O Z, t" u -
1 h( W$ q5 n! i, f( w1 z/ a: S) u -
3 W$ p; t0 _( \0 t0 \$ F0 C$ a- y - , l' S- f8 a* Z% }! q
- //************4.图像识别************
# i' ]. O% f+ b0 P - $url = "http://japi.juhe.cn/image_recognition/check";: J8 ~( [4 M& p! p, U6 [
- $params = array(7 H( o- g. c+ X+ b6 U! ~
- "file" => "",//上传的图片
# D( n; ~/ n" j- J, t% S - "key" => $appkey,//APP Key. t) r% x8 I* Q: I- F2 o5 f( Q$ k5 Q
- "pname" => "",//包名
* a' y: w& M; r# L5 M - "device_name" => "",//设备名称(如android OS或iphone OS)1 E3 N. m: Q! b# \5 n7 f* f7 V- i! T
- "device_version" => "",//设备版本(如:4.0.3)
+ w* {( Z2 ~7 T) {9 } - "latitude" => "",//纬度" D2 v5 j: {1 X: z! ?, O
- "longitude" => "",//经度
, _3 K0 u: G9 Q0 { - "uuid" => "",//设备id1 ^4 d) m2 ]1 V( ~/ X9 a. ?- A
- "zone" => "",//请求地区
/ ]' |' A9 ?0 h, S3 | - );
/ o# T8 s3 s, J0 r; I - $paramstring = http_build_query($params);
0 A0 j5 b4 t% Y - $content = juhecurl($url,$paramstring,1);
0 r$ \1 v7 q, ^" R" D1 i+ Y0 u: I - $result = json_decode($content,true);
2 |8 c& d3 x" X2 T2 u1 M Z' { - if($result){
# }) B9 x# {. B0 r# e9 [ - if($result['error_code']=='0'){: E, z: O& N' k$ }; F# A8 y
- print_r($result);
0 T* d$ k! E% s: v/ h7 w' [+ V0 f - }else{
c2 y i3 f3 K; ~" t - echo $result['error_code'].":".$result['reason'];
( w7 Q! D) D" j! L- D/ @ - }
+ Z, i0 D' @8 e9 a1 b/ o - }else{2 T: x# R6 z; W+ v" r, {
- echo "请求失败";& G7 A8 m( P" e( O8 l/ C4 S' s& T- H4 w
- }3 N ?1 E) Z: E% ?8 |1 g }
- //**************************************************
. i" `7 r1 D0 d. r, p: B8 B2 I4 H -
& b$ {6 {1 I+ v2 @& G% e5 J5 h -
& e; c8 b- N. f% N7 ~# h# u0 T - . y$ H1 w% i) z4 J
- : k' J& F! ~. [" }
-
8 n/ |; l/ g5 Q- y/ \; t - /** n3 J! q$ [; i4 y1 S" n* n
- * 请求接口返回内容% [4 x! W J4 f' G: b6 Y
- * @param string $url [请求的URL地址]* l, H# @1 p7 v0 |3 _$ q
- * @param string $params [请求的参数]
! }/ j4 |8 u% C) K9 L# Z - * @param int $ipost [是否采用POST形式]
' o& u s# g! i4 }+ ~ - * @return string
" M2 q/ Z6 |6 S: K/ q; o4 o+ s( ~8 k - */# m" R1 ]: M {* i9 \# H
- function juhecurl($url,$params=false,$ispost=0){
: G' N( ~ H- R/ K - $httpInfo = array();" U% X3 s* l: t9 m- }0 V* I4 g
- $ch = curl_init();* b0 C! Z: q% o# Q1 T" K1 h3 n0 N
- ' s) O& k9 P6 H0 u, p
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );% V t1 H F( \
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
: f1 r2 U A& [ - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );3 q$ g4 t/ X' |7 a$ Q/ P
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);. {; d. z+ k+ q
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );" L5 @1 x* J- v" w# ?
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
: x- i7 Y7 F; F1 Z - if( $ispost )& f1 g% H: b: R0 Y# K
- {( H0 T' O* k7 q& T' P8 G/ W
- curl_setopt( $ch , CURLOPT_POST , true );1 o. B6 h4 F% V4 H! Y) a& Y4 X
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );- ?# ?* W9 d! B. a" s
- curl_setopt( $ch , CURLOPT_URL , $url );
8 L! J: a/ o! \" g9 i# f - }9 y7 F3 Y9 |0 J; {6 I1 U
- else1 {# b4 m4 Y6 v/ F( x
- {
1 I( |! J% I) \' A' Q* ^7 u - if($params){$ N2 i. h* S) O: m
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );9 R6 @ K" Q R
- }else{' b# E% ~0 k( ]0 h. n& e7 M
- curl_setopt( $ch , CURLOPT_URL , $url);: k7 }4 m# j9 t% ^1 O
- }
# \( m2 i4 ]; E$ a3 m - }$ ^+ r8 C3 B, s- M7 t
- $response = curl_exec( $ch );
: o: ?- l8 e% p& j6 n" M5 _ - if ($response === FALSE) {
% N9 f" e8 M2 L - //echo "cURL Error: " . curl_error($ch);! V3 J4 I c, I. [, ?) P- Y" J
- return false;
/ E5 K/ ]; T; i - }
$ I) r- o: d$ J n - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
% h7 F$ c5 [/ z - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
+ Z. i: O E1 E. b) ~# j& \8 W - curl_close( $ch );
# v/ g: s9 z2 V* o' [4 g - return $response;0 o S8 o l& a. ?
- }
复制代码 $ \" L6 m- K, `1 G7 v0 f, K
' ^- [8 K1 Q' Y' I! F. \5 y6 [
|
|